diff -Naur asterisk_org/callerid.c asterisk_cid/callerid.c --- asterisk_org/callerid.c 2005-11-30 17:49:58.000000000 +0900 +++ asterisk_cid/callerid.c 2005-12-06 23:28:41.000000000 +0900 @@ -56,6 +56,10 @@ int flags; int sawflag; int len; + + unsigned short crc_checksum ; + char cidgetbuf[1024] ; + int ncidbfpos ; }; @@ -251,6 +255,192 @@ return 0; } +int sub_dump_take(char *pdata,int nlen) +{ + char tmpbuf[1024] ; + char wrkbuf[1024] ; + int i ; + int n_cnt ; + n_cnt = 0 ; + while (1) { + memset(tmpbuf, 0, sizeof(tmpbuf)) ; + sprintf(tmpbuf, "%04X:", n_cnt) ; + for (i=0; i<16; i++) { + sprintf(wrkbuf, "%02X ", (unsigned char)pdata[n_cnt++]) ; + strcat(tmpbuf, wrkbuf) ; + if (n_cnt >= nlen) { + break ; + } + } + ast_log(LOG_NOTICE, "DUMP:%s\n", tmpbuf) ; + if (n_cnt >= nlen) { + break ; + } + } + return 0 ; +} + +int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int len, int codec) +{ + int mylen = len; + int olen; + int b = 'X'; + int b2 ; + int res; + int x; + short *buf = malloc(2 * len + cid->oldlen); + short *obuf = buf; + + if (!buf) { + ast_log(LOG_WARNING, "Out of memory\n"); + return -1; + } + + memset(buf, 0, 2 * len + cid->oldlen); + memcpy(buf, cid->oldstuff, cid->oldlen); + mylen += cid->oldlen/2; + + for (x=0;xoldlen/2] = AST_XLAW(ubuf[x]); + + while (mylen >= 160) { + b = b2 = 0 ; + olen = mylen; + res = fsk_serie(&cid->fskd, buf, &mylen, &b); + + if (mylen < 0) { + ast_log(LOG_ERROR, "fsk_serie made mylen < 0 (%d)\n", mylen); + return -1; + } + + buf += (olen - mylen); + + if (res < 0) { + ast_log(LOG_NOTICE, "fsk_serie failed\n"); + return -1; + } + + if (res == 1) { + /* Ignore invalid bytes */ + if (b > 0xff) { + if (cid->sawflag < 14) { + ast_log(LOG_WARNING, "INVALID %d Ignoring (%c:%X)\n", cid->sawflag,b,b) ; + continue; + } else { + ast_log(LOG_WARNING, "INVALID %d found (%c:%X)\n", cid->sawflag,b,b) ; + } + } + + b2 = b ; + b = b & 0x7f ; + cid->cidgetbuf[cid->ncidbfpos++] = (unsigned char)b ; + + switch(cid->sawflag) { + case 0: // Wait for DLE + if (b == 0x10) { + cid->sawflag = 1; + cid->ncidbfpos = 0 ; + cid->cidgetbuf[cid->ncidbfpos++] = (unsigned char)b ; + } + break; + case 1: // Wait for SOH + if (b == 0x01) { + cid->sawflag = 2 ; + } + break ; + case 2: // Wait for HEADER + if (b == 0x07) { + cid->sawflag = 3 ; + } + break; + case 3: // Wait for DLE + if (b == 0x10) { + cid->sawflag = 4 ; + } + break; + case 4: // Wait for STX + if (b == 0x02) { + cid->sawflag = 5 ; + } + break; + case 5: // SERVICE TYPE + cid->sawflag = 6 ; + break; + case 6: // Length + if (b == 0x10) { + cid->sawflag = 107 ; + } else { + cid->sawflag = 7 ; + } + break; + case 7: // get NUMBER TYPE + if (b == 0x10) { + cid->sawflag = 108 ; + } else { + cid->sawflag = 8 ; + } + break; + case 8: // get NUMBER LENGTH + if (b == 0x10) { + cid->sawflag = 109 ; + } else { + cid->sawflag = 9 ; + } + cid->len = b; + cid->pos = 0; + break; + case 9: /* Retrieve message */ + cid->rawdata[cid->pos++] = b; + cid->len--; + if (!cid->len) { + cid->rawdata[cid->pos] = '\0'; + cid->sawflag = 10; + } + break; + case 10: // DLE + cid->sawflag = 11; + break; + case 11: // ETX + cid->sawflag = 12; + break; + case 12: // get CRC Checksum 1 + cid->sawflag = 13; + break; + case 13: // get CRC Checksum 2 + cid->sawflag = 14; + break; + case 14: /* Check checksum 2 bytes */ + sub_dump_take(cid->cidgetbuf, cid->ncidbfpos) ; + cid->number[0] = '\0'; + cid->name[0] = '\0'; + ast_copy_string(cid->number, cid->rawdata, sizeof(cid->number)); + cid->flags = 0 ; + return 1; + break; + case 107: + cid->sawflag = 7 ; + break ; + case 108: + cid->sawflag = 8 ; + break ; + case 109: + cid->sawflag = 9 ; + break ; + default: + ast_log(LOG_ERROR, "invalid value in sawflag %d\n", cid->sawflag); + } + } + } + if (mylen) { + memcpy(cid->oldstuff, buf, mylen * 2); + cid->oldlen = mylen * 2; + } else + cid->oldlen = 0; + free(obuf); + return 0; +} + + int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, int codec) { int mylen = len; diff -Naur asterisk_org/channels/chan_zap.c asterisk_cid/channels/chan_zap.c --- asterisk_org/channels/chan_zap.c 2005-11-30 17:49:59.000000000 +0900 +++ asterisk_cid/channels/chan_zap.c 2005-12-06 23:29:44.000000000 +0900 @@ -5188,6 +5188,10 @@ int len = 0; int res; int index; + + int country_num = 0 ; + + if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Starting simple switch on '%s'\n", chan->name); index = zt_get_index(chan, p, 1); @@ -5824,6 +5828,14 @@ number = 0; /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */ } else if (p->cid_signalling == CID_SIG_V23) { + + ast_log(LOG_NOTICE, "ROUTE:LANG = (%s)\n", p->language ) ; + ast_log(LOG_NOTICE, "ROUTE:CONTEXT = (%s)\n", p->context ) ; + + if ( !strcmp( p->language, "jp" ) ) { + country_num = 81; + } + cs = callerid_new(cid_signalling); if (cs) { samples = 0; @@ -5845,8 +5857,19 @@ if (i & ZT_IOMUX_SIGEVENT) { res = zt_get_event(p->subs[index].zfd); ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res)); - res = 0; - break; + + if (country_num == 81) { + if (res == 18) { + ast_log(LOG_NOTICE, "OFF HOOK\n") ; + res = zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK); + usleep(1); + } + } + else + { + res = 0; + break; + } } else if (i & ZT_IOMUX_READ) { res = read(p->subs[index].zfd, buf, sizeof(buf)); if (res < 0) { @@ -5859,7 +5882,13 @@ break; } samples += res; - res = callerid_feed(cs, buf, res, AST_LAW(p)); + + if (country_num == 81) { + res = callerid_feed_jp(cs, buf, res, AST_LAW(p)); + } else { + res = callerid_feed(cs, buf, res, AST_LAW(p)); + } + if (res < 0) { ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno)); break; @@ -5871,15 +5900,23 @@ } if (res == 1) { callerid_get(cs, &name, &number, &flags); - if (option_debug) - ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags); + ast_log(LOG_NOTICE, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags); } if (res < 0) { ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name); } - /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */ - res = 2000; + if (country_num == 81) { + ast_log(LOG_NOTICE, "ON HOOK \n" ) ; + res = zt_set_hook(p->subs[SUB_REAL].zfd, ZT_ONHOOK); + usleep(1); + res = 4000; + } else { + + /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */ + res = 2000; + } + for (;;) { struct ast_frame *f; res = ast_waitfor(chan, res); diff -Naur asterisk_org/include/asterisk/callerid.h asterisk_cid/include/asterisk/callerid.h --- asterisk_org/include/asterisk/callerid.h 2005-11-07 00:09:47.000000000 +0900 +++ asterisk_cid/include/asterisk/callerid.h 2005-12-03 17:16:48.000000000 +0900 @@ -91,6 +91,7 @@ * and 1 if the CallerID spill reception is complete. */ extern int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int samples, int codec); +extern int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int samples, int codec); /*! \brief Extract info out of callerID state machine. Flags are listed above * \param cid Callerid state machine to act upon