diff --git a/chan_capi.c b/chan_capi.c index aa6ed5d..266552f 100644 --- a/chan_capi.c +++ b/chan_capi.c @@ -222,7 +222,7 @@ static struct capi_pvt* get_active_plci (struct ast_channel *c); static _cstruct diva_get_b1_conf (struct capi_pvt *i); static void clear_channel_fax_loop (struct ast_channel *c, struct capi_pvt *i); static struct ast_channel* capidev_acquire_locks_from_thread_context (struct capi_pvt *i); -static int pbx_capi_add_diva_protocol_independent_extension (struct capi_pvt *i, unsigned char (*facilityarray)[CAPI_MAX_FACILITYDATAARRAY_SIZE]); +static void pbx_capi_add_diva_protocol_independent_extension (struct capi_pvt *i, unsigned char *facilityarray, struct ast_channel *c, const char* variable); /* * B protocol settings @@ -1026,7 +1026,10 @@ static int pbx_capi_alert(struct ast_channel *c) } facilityarray = alloca(CAPI_MAX_FACILITYDATAARRAY_SIZE); + facilityarray[0] = 0; cc_qsig_add_call_alert_data(facilityarray, i, c); + pbx_capi_add_diva_protocol_independent_extension (i, facilityarray, c, "CALLEDNAME"); + if (capi_sendf(NULL, 0, CAPI_ALERT_REQ, i->PLCI, get_capi_MessageNumber(), "(()()()s())", facilityarray @@ -1567,16 +1570,11 @@ static int pbx_capi_call(struct ast_channel *c, char *idest, int timeout) pbx_capi_call_build_calling_party_number (c, calling, sizeof(calling), use_defaultcid, ocid); if (doqsig != 0) { - if (i->qsigfeat != 0) { - facilityarray = alloca(CAPI_MAX_FACILITYDATAARRAY_SIZE); + facilityarray = alloca(CAPI_MAX_FACILITYDATAARRAY_SIZE); + facilityarray[0] = 0; + if (i->qsigfeat != 0) cc_qsig_add_call_setup_data(facilityarray, i, c); - } else { - unsigned char tmp[CAPI_MAX_FACILITYDATAARRAY_SIZE]; - if (pbx_capi_add_diva_protocol_independent_extension (i, &tmp) == 0) { - facilityarray = alloca(CAPI_MAX_FACILITYDATAARRAY_SIZE); - memcpy (facilityarray, tmp, CAPI_MAX_FACILITYDATAARRAY_SIZE); - } - } + pbx_capi_add_diva_protocol_independent_extension (i, facilityarray, NULL, "CALLED/CONNECTED NAME"); } #ifdef DIVA_STREAMING @@ -1705,6 +1703,7 @@ static int capi_send_answer(struct ast_channel *c, _cstruct b3conf) facilityarray = alloca(CAPI_MAX_FACILITYDATAARRAY_SIZE); cc_qsig_add_call_answer_data(facilityarray, i, c); + pbx_capi_add_diva_protocol_independent_extension (i, facilityarray, c, "CONNECTEDNAME"); if (i->ntmode) { /* in NT-mode we send the current local time to device */ @@ -8876,36 +8875,52 @@ int pbx_capi_streaming_supported (struct capi_pvt *i) } #endif -static int pbx_capi_add_diva_protocol_independent_extension (struct capi_pvt *i, unsigned char (*facilityarray)[CAPI_MAX_FACILITYDATAARRAY_SIZE]) +/*! + * \brief Used to provide 'Name' info element to network. Name is provided in generoc format and is automatically converted by Diva protocol code + * to required format with respect to call state (automatic name type). If name is not supported by protocol then information element is silently discarded. + * Can be used with QSIG and any other protocol which supports names. + */ +static void pbx_capi_add_diva_protocol_independent_extension (struct capi_pvt *i, unsigned char *facilityarray, struct ast_channel *c, const char* variable) { - char* cid_name = 0; + const char* cid_name = 0; - if (i->divaqsig == 0) - return (-1); + if (i->qsigfeat != 0 || i->divaqsig == 0) + return; + + if (c != 0 && variable != 0) { + cid_name = pbx_builtin_getvar_helper(c, variable); + if (cid_name != 0 && *cid_name == 0) + cid_name = 0; + } #ifdef CC_AST_HAS_VERSION_1_8 - if (i->owner->connected.id.name.valid ) { + if (cid_name == 0 && i->owner->connected.id.name.valid ) { cid_name = ast_strdupa(S_COR(i->owner->connected.id.name.valid, i->owner->connected.id.name.str, "")); } #else - if (i->owner->cid.cid_name && *i->owner->cid.cid_name) { + if (cid_name == 0 && i->owner->cid.cid_name && *i->owner->cid.cid_name) { cid_name = ast_strdupa(i->owner->cid.cid_name); } #endif - if (cid_name != 0) { + if (cid_name != 0 && *cid_name == 0) + cid_name = i->name; + + if (cid_name != 0 && *cid_name != 0) { unsigned char* p; int length = strlen (cid_name); const unsigned char t[] = { 0x0d /* 0 - len */, 0x1c, 0x0b /* 2 - len */, 0x9f, 0xa1, 0x08 /* 5 - len */, 0x02, 0x01, 0x01, 0x02, 0x01, 0x00, 0x80, 0x00 /* 12+1 - len */ }; - p = *facilityarray; + p = facilityarray; memcpy (p, t, sizeof(t)); memcpy (p+sizeof(t), cid_name, MIN(length, (CAPI_MAX_FACILITYDATAARRAY_SIZE-sizeof(t)))); p[0] += length; p[2] += length; p[5] += length; p[12+1] += length; + + cc_verbose(3, 0, VERBOSE_PREFIX_3 "%s: * Sending %s %02x '%s'\n", i->vname, variable, 0x80, cid_name); } - return (0); + return; }