--- chan_dahdi.c.158482 2008-12-24 20:33:48.000000000 +1300 +++ chan_dahdi.c 2009-01-16 12:33:25.000000000 +1300 @@ -7641,25 +7677,47 @@ static int mwi_send_init(struct dahdi_pv { int x, res; - pvt->mwisendactive = 1; - pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL; /*Assume FSK only */ +#ifdef DAHDI_VMWI_FSK /* Determine how this spill is to be sent */ - if(mwisend_rpas) { + if (pvt->mwisendtype & DAHDI_VMWI_RPAS) { pvt->mwisend_data.mwisend_current = MWI_SEND_SA; - } - - pvt->cidspill = ast_calloc(1, MAX_CALLERID_SIZE); - if (!pvt->cidspill) { + pvt->mwisendactive = 1; + } else if (pvt->mwisendtype & DAHDI_VMWI_FSK) { + pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL; + pvt->mwisendactive = 1; + } else { pvt->mwisendactive = 0; - return -1; + return 0; } - x = DAHDI_FLUSH_BOTH; - res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_FLUSH, &x); - x = 3000; - ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_ONHOOKTRANSFER, &x); - pvt->cidlen = vmwi_generate(pvt->cidspill, has_voicemail(pvt), CID_MWI_TYPE_MDMF_FULL, + ast_log(LOG_WARNING, "VMWI_FSK mwisend_current = %d\n", pvt->mwisend_data.mwisend_current); +#else + if (mwisend_rpas) { + pvt->mwisend_data.mwisend_current = MWI_SEND_SA; + } + ast_log(LOG_WARNING, "NO VMWI_FSK mwisend_current = %d\n", pvt->mwisend_data.mwisend_current); +#endif + + if (pvt->cidspill) { + ast_log(LOG_WARNING, "cidspill already exists??\n"); + ast_free(pvt->cidspill); + pvt->cidspill = NULL; + pvt->cidpos = 0; + pvt->cidlen = 0; + } + pvt->cidspill = ast_calloc(1, MAX_CALLERID_SIZE); + if (!pvt->cidspill) { + pvt->mwisendactive = 0; + return -1; + } + x = DAHDI_FLUSH_BOTH; + res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_FLUSH, &x); + x = 3000; + ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_ONHOOKTRANSFER, &x); + if (pvt->mwisendtype & DAHDI_VMWI_FSK) { + pvt->cidlen = vmwi_generate(pvt->cidspill, has_voicemail(pvt), CID_MWI_TYPE_MDMF_FULL, AST_LAW(pvt), pvt->cid_name, pvt->cid_num, 0); - pvt->cidpos = 0; + pvt->cidpos = 0; + } return 0; } @@ -7676,54 +7734,64 @@ static int mwi_send_process_buffer(struc } else if (MWI_SEND_DONE != pvt->mwisend_data.mwisend_current) { /* Normal processing -- Perform mwi send action */ switch ( pvt->mwisend_data.mwisend_current) { - case MWI_SEND_SA: - /* Send the Ring Pulse Signal Alert */ - res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &AS_RP_cadence); - if (res) { - ast_log(LOG_WARNING, "Unable to set RP-AS ring cadence: %s\n", strerror(errno)); - goto quit; - } - res = dahdi_set_hook(pvt->subs[SUB_REAL].dfd, DAHDI_RING); - pvt->mwisend_data.mwisend_current = MWI_SEND_SA_WAIT; - break; - case MWI_SEND_SA_WAIT: /* do nothing until I get RINGEROFF event */ - break; - case MWI_SEND_PAUSE: /* Wait between alert and spill - min of 500 mS*/ + case MWI_SEND_SA: + /* Send the Ring Pulse Signal Alert */ + res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &AS_RP_cadence); + if (res) { + ast_log(LOG_WARNING, "Unable to set RP-AS ring cadence: %s\n", strerror(errno)); + goto quit; + } + res = dahdi_set_hook(pvt->subs[SUB_REAL].dfd, DAHDI_RING); + pvt->mwisend_data.mwisend_current = MWI_SEND_SA_WAIT; + break; + case MWI_SEND_SA_WAIT: /* do nothing until I get RINGEROFF event */ + break; + case MWI_SEND_PAUSE: /* Wait between alert and spill - min of 500 mS*/ +#ifdef DAHDI_VMWI_FSK + if (pvt->mwisendtype & DAHDI_VMWI_FSK) { +#endif gettimeofday(&now, NULL); if ((int)(now.tv_sec - pvt->mwisend_data.pause.tv_sec) * 1000000 + (int)now.tv_usec - (int)pvt->mwisend_data.pause.tv_usec > 500000) { pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL; + ast_log(LOG_WARNING, "mwisend_current = %d\n", pvt->mwisend_data.mwisend_current); } - break; - case MWI_SEND_SPILL: - /* We read some number of bytes. Write an equal amount of data */ - if(0 < num_read) { - if (num_read > pvt->cidlen - pvt->cidpos) - num_read = pvt->cidlen - pvt->cidpos; - res = write(pvt->subs[SUB_REAL].dfd, pvt->cidspill + pvt->cidpos, num_read); - if (res > 0) { - pvt->cidpos += res; - if (pvt->cidpos >= pvt->cidlen) { - pvt->mwisend_data.mwisend_current = MWI_SEND_CLEANUP; - } - } else { - ast_log(LOG_WARNING, "MWI Send Write failed: %s\n", strerror(errno)); - goto quit; +#ifdef DAHDI_VMWI_FSK + } else { /* support for mwisendtype=nofsk */ + pvt->mwisend_data.mwisend_current = MWI_SEND_CLEANUP; + } +#endif + break; + case MWI_SEND_SPILL: + /* We read some number of bytes. Write an equal amount of data */ + if(0 < num_read) { + if (num_read > pvt->cidlen - pvt->cidpos) + num_read = pvt->cidlen - pvt->cidpos; + res = write(pvt->subs[SUB_REAL].dfd, pvt->cidspill + pvt->cidpos, num_read); + if (res > 0) { + pvt->cidpos += res; + if (pvt->cidpos >= pvt->cidlen) { + ast_log(LOG_WARNING, "MWI_SEND_SPILL mwisend_current = %d\n", pvt->mwisend_data.mwisend_current); + pvt->mwisend_data.mwisend_current = MWI_SEND_CLEANUP; } + } else { + ast_log(LOG_WARNING, "MWI Send Write failed: %s\n", strerror(errno)); + goto quit; } - break; - case MWI_SEND_CLEANUP: - /* For now, do nothing */ - pvt->mwisend_data.mwisend_current = MWI_SEND_DONE; - break; - default: - /* Should not get here, punt*/ - goto quit; - break; + } + break; + case MWI_SEND_CLEANUP: + /* For now, do nothing */ + pvt->mwisend_data.mwisend_current = MWI_SEND_DONE; + break; + default: + /* Should not get here, punt*/ + goto quit; + break; } } if (MWI_SEND_DONE == pvt->mwisend_data.mwisend_current) { - if(pvt->cidspill) { + if (pvt->cidspill) { ast_free(pvt->cidspill); pvt->cidspill = NULL; pvt->cidpos = 0; @@ -7733,6 +7801,13 @@ static int mwi_send_process_buffer(struc } return 0; quit: + if (pvt->cidspill) { + ast_free(pvt->cidspill); + pvt->cidspill = NULL; + pvt->cidpos = 0; + pvt->cidlen = 0; + } + pvt->mwisendactive = 0; return -1; }