diff --git a/libvoice/common.c b/libvoice/common.c index e721b1971647d20c7a4cb3506aca6f2608cff18a..d9b6e5efc0d830475b070bf7233ec61c112d2069 100644 --- a/libvoice/common.c +++ b/libvoice/common.c @@ -81,7 +81,7 @@ const struct voice_signal_t signal_map[] = { // List of signals requested by Ast }; // Callback function which is invoked when an event is detected from the voice engine -void (*voice_cb_event_report)(int line, const char *event, int data) = NULL; +void (*voice_cb_event_report)(int line, const char *event, const char *data) = NULL; // Callback function which is invoked when an encoded media packet is generated by the voice engine void (*voice_cb_egress_media)(const struct media_packet_t *packet, int size) = NULL; @@ -169,7 +169,7 @@ int voice_line_deinit(void) { } // Register the callback function for event report -int voice_register_cb_event_report(void (*cb_event_report)(int line, const char *event, int data)) { +int voice_register_cb_event_report(void (*cb_event_report)(int line, const char *event, const char *data)) { voice_cb_event_report = cb_event_report; return 0; diff --git a/libvoice/libvoice.h b/libvoice/libvoice.h index e72dda8bb28e74e904f57f9ff2a2ec1a9abf4451..55a6fd9569cca8dd866973ea2319f537d76933a0 100644 --- a/libvoice/libvoice.h +++ b/libvoice/libvoice.h @@ -155,6 +155,9 @@ struct line_t { int pcm_callid[2]; // -1: Invalid, 0: Obtaining, >0: Established pe_list_t *pending_digits; // List of keypad digits waiting to be sent enum PAGING_STATUS paging_status; // Line's paging status +#define VOICEMNGR_LINE_FLAG_NARROW_BAND_ONLY 0x1 + uint32_t flags; + void *priv; // Platform dependent data }; @@ -267,7 +270,7 @@ extern const struct voice_event_t event_map[]; extern const struct dect_event_t dect_event_map[]; extern const struct voice_signal_t signal_map[]; -extern void (*voice_cb_event_report)(int line, const char *event, int data); +extern void (*voice_cb_event_report)(int line, const char *event, const char *data); extern void (*voice_cb_egress_media)(const struct media_packet_t *packet, int size); @@ -303,7 +306,7 @@ void voice_hook_simulation_maintain(int line); int voice_get_rtp_stats(int line, int connection, int reset, struct rtp_stats_t *rtp_stats); int voice_get_codec_capability(struct codec_capability *pcodecs); int voice_set_country(const char *country_code); -int voice_register_cb_event_report(void (*voice_cb_event_report)(int line, const char *event, int data)); +int voice_register_cb_event_report(void (*voice_cb_event_report)(int line, const char *event, const char *data)); int voice_register_cb_egress_media(void (*cb_egress_media)(const struct media_packet_t *packet, int size)); int voice_write_media_packet(const struct media_packet_t *packet); diff --git a/libvoice/voice-types.h b/libvoice/voice-types.h index 6bffd0e3b5adb901ab07dd6de4e78f1d2c284412..38bdb78bfbff8af6897726f5e795d72c0a0a250b 100644 --- a/libvoice/voice-types.h +++ b/libvoice/voice-types.h @@ -82,5 +82,7 @@ enum hangup_cause { #define DECTMNGR_RPC_PARAM_EXTENSION_ID "extension_id" #define DECTMNGR_RPC_PARAM_PCM_ID "pcm_id" #define DECTMNGR_RPC_PARAM_HANGUPCAUSE "hangupcause" +// Parameter values +#define EVENT_DATA_NARROW_BAND_ONLY "narrow_band_only" #endif diff --git a/line.c b/line.c index b01c16514eb1eda08c70065e91e2865e6d474198..bc340d296685cbcef4ae2cf24b5d56384d8207dc 100644 --- a/line.c +++ b/line.c @@ -55,7 +55,7 @@ static int send_dect_event_to_asterisk(int line, struct dect_event_t dectEvnt) msg = malloc(sizeof(struct line_event_t)); msg->name = dectEvnt.name; - msg->data = 0; + msg->data = NULL; msg->line = line; ubus_call_asterisk(msg); @@ -88,7 +88,7 @@ static int perhaps_simulate_busy(int line, struct voice_ubus_req_t *ubus_req) msg = malloc(sizeof(struct line_event_t)); if (msg) { msg->name = ev->name; - msg->data = 0; + msg->data = NULL; msg->line = line; send_event_main(msg, EVENT_MAIN_LINE); } else { @@ -651,14 +651,14 @@ int line_update_connection_by_pbx(int line, int pcm_callid) // Reception of a create connection request from dectmngr. // Generate a off-hook event and queue the request // until Asterisk acknowledge the offh-ook event. -int line_new_connection_by_dect(int line, const char *cid, int pcm, struct voice_ubus_req_t *ubus_req) +int line_new_connection_by_dect(int line, const char *cid, int pcm, const char *data, struct voice_ubus_req_t *ubus_req) { struct line_req_t *line_req; if (!voice_line_is_ready(line) || lines[line].type != VOICE_LINE_DECT) return -1; - ENDPT_DBG("line=%d, pcm=%d, cid=%s\n", line, pcm, cid); + ENDPT_DBG("line=%d, pcm=%d, cid=%s, data=%s\n", line, pcm, cid, data ? data : "<null>"); pcm_states_dump(__func__, line); if (is_valid_pcm_id(pcm)) { @@ -668,6 +668,12 @@ int line_new_connection_by_dect(int line, const char *cid, int pcm, struct voice } if (!voice_line_is_offhook(line)) { + if (data && strcmp(data, EVENT_DATA_NARROW_BAND_ONLY) == 0) { + lines[line].flags |= VOICEMNGR_LINE_FLAG_NARROW_BAND_ONLY; + ENDPT_DBG("The DECT handset which goes off hook supports narrow band only\n"); + } else { + lines[line].flags &= ~VOICEMNGR_LINE_FLAG_NARROW_BAND_ONLY; + } if (voice_line_simulate_hook(line, VOICE_EVT_OFFHOOK)) return -1; } else { @@ -734,7 +740,7 @@ int line_close_connection_by_dect(int line, int pcm, struct voice_ubus_req_t *ub msg = malloc(sizeof(struct line_event_t)); if (msg) { msg->name = "DECT_UNAVAILABLE"; - msg->data = 0; + msg->data = NULL; msg->line = line; send_event_main(msg, EVENT_MAIN_LINE); } @@ -753,7 +759,7 @@ int line_close_connection_by_dect(int line, int pcm, struct voice_ubus_req_t *ub msg = malloc(sizeof(struct line_event_t)); if (msg) { msg->name = "CALL_REJECT"; - msg->data = 0; + msg->data = NULL; msg->line = line; send_event_main(msg, EVENT_MAIN_LINE); } diff --git a/line.h b/line.h index 29a51bcbf20566973f6b3257fd951fc8c6b44043..850fc9229ef12a58e3ebc43438a36aec58545438 100644 --- a/line.h +++ b/line.h @@ -19,9 +19,9 @@ enum line_action_t { // Event sent with UBUS when something has happened with a phone line struct line_event_t { - const char *name; // String communicated with Asterisk - int data; // True/false is a DTMF button is pressed/depressed - int line; // Line number + const char *name; // String communicated with Asterisk + const char *data; // Event specific data + int line; // Line number }; // Deferred UBUS request @@ -61,7 +61,7 @@ int line_new_connection_by_asterisk(int line, int connection, struct voice_ubus_ int line_close_connection_by_asterisk(int line, int connection, struct voice_ubus_req_t *ubus_req); int line_release_connection_by_asterisk(int line, int connection, struct voice_ubus_req_t *ubus_req); int line_update_connection_by_pbx(int line, int pcm_callid); -int line_new_connection_by_dect(int line, const char *cid, int pcm, struct voice_ubus_req_t *ubus_req); +int line_new_connection_by_dect(int line, const char *cid, int pcm, const char *data, struct voice_ubus_req_t *ubus_req); int line_connection_parm_update_by_asterisk(int line, int connection, struct config_update_struct *data); int line_close_connection_by_dect(int line, int pcm, struct voice_ubus_req_t *ubus_req); int line_signal(int line, const char *signame, const char *data, struct voice_ubus_req_t *ubus_req); diff --git a/main.c b/main.c index 9f9c3ee2de74af53ad4d43ebe8f33ab49032352f..16b91327e66612983caa518aa34bd68d73e05852 100644 --- a/main.c +++ b/main.c @@ -96,7 +96,7 @@ static void event_stream_handler(pe_stream_t *stream __attribute__((unused)), pe case EVENT_MAIN_LINE: ev = (struct line_event_t*) pe_list_get(event_list); if(!ev) break; - ENDPT_DBG("Main event handler line %d event %s\n", ev->line, ev->name); + ENDPT_DBG("Main event handler line %d event %s data %s\n", ev->line, ev->name, ev->data ? ev->data : "<null>"); ubus_call_asterisk(ev); ubus_broadcast_event(ev); // Also broadcast event to all break; @@ -199,7 +199,7 @@ static int signals_init(void) { return 0; } -static void voicemngr_event_report(int line, const char *event, int data) { +static void voicemngr_event_report(int line, const char *event, const char *data) { /* Re-send the event to the main thread, which in turn re-send * to Asterisk. We need to do this due to UBUS is not thread safe, * so all UBUS calls must be done from a single thread. */ @@ -211,7 +211,7 @@ static void voicemngr_event_report(int line, const char *event, int data) { return; } msg->name = event; - msg->data = (data < 0 ? 0 : data); // Discard negative values + msg->data = data; msg->line = line; send_event_main(msg, EVENT_MAIN_LINE); } diff --git a/ubus.c b/ubus.c index ba82456e5adb5db1ceb6cd982e15eb1b2d981ce8..01cfd364cf31e585d1d95fff5a02cd985041fd0a 100644 --- a/ubus.c +++ b/ubus.c @@ -76,6 +76,7 @@ enum { DECT_CALLER_NAME, // Caller Name DECT_SIP_CLIENT_ID, DECT_PCM_ID, // PCM ID + DECT_DATA, // Extra parameter which is request (call creation, release, and etc.) specific }; // Keeping track of sent but not yet answered UBUS requests, for timeout. @@ -179,6 +180,7 @@ static const struct blobmsg_policy request_call_policy[] = { [DECT_CALLER_NAME] = { .name = "caller_name", .type = BLOBMSG_TYPE_STRING }, [DECT_SIP_CLIENT_ID] = { .name = "sip_client_id", .type = BLOBMSG_TYPE_INT32 }, [DECT_PCM_ID] = { .name = "pcm_id", .type = BLOBMSG_TYPE_INT32 }, + [DECT_DATA] = { .name = "data", .type = BLOBMSG_TYPE_STRING }, }; // Our ubus RPC methods @@ -877,15 +879,9 @@ static int ubus_request_call(struct ubus_context *uctx, struct ubus_object *obj struct blob_attr *msg) { struct blob_attr *keys[ARRAY_SIZE(request_call_policy)]; - int termId, pcmId, add, release; + int termId = -1, pcmId = -1, add = 0, release = 0; struct voice_ubus_req_t ubusReq; - const char *cid; - - termId = -1; - pcmId = -1; - add = 0; - release = 0; - cid = NULL; + const char *cid = NULL, *data = NULL; // Tokenize message key/value paris into an array if(blobmsg_parse(request_call_policy, ARRAY_SIZE(request_call_policy), @@ -915,7 +911,12 @@ static int ubus_request_call(struct ubus_context *uctx, struct ubus_object *obj if(keys[DECT_PCM_ID]) { pcmId = blobmsg_get_u32(keys[DECT_PCM_ID]); - ENDPT_DBG("pcmId %d\n", pcmId); + ENDPT_DBG("call pcmId %d\n", pcmId); + } + + if(keys[DECT_DATA]) { + data = blobmsg_get_string(keys[DECT_DATA]); + ENDPT_DBG("call data %s\n", data); } if((pcmId & 0xFFFF) < CALL_DEFAULT0 || (pcmId & 0xFFFF) >= CALL_LAST) { @@ -935,7 +936,7 @@ static int ubus_request_call(struct ubus_context *uctx, struct ubus_object *obj return UBUS_STATUS_UNKNOWN_ERROR; } } else if(add && termId >= 0) { - if(line_new_connection_by_dect(dectmngr_line_to_voicemngr_line(termId), cid, pcmId, &ubusReq)) { + if (line_new_connection_by_dect(dectmngr_line_to_voicemngr_line(termId), cid, pcmId, data, &ubusReq)) { send_reply_dectmngr(&ubusReq, termId, pcmId, UBUS_STATUS_UNKNOWN_ERROR); return UBUS_STATUS_UNKNOWN_ERROR; } @@ -948,7 +949,7 @@ static int ubus_request_call(struct ubus_context *uctx, struct ubus_object *obj struct line_event_t *ast_msg = malloc(sizeof(struct line_event_t)); if (ast_msg) { ast_msg->name = pcmId == CALL_MODE_MULTIPLE ? "LINE_CALL_MODE_MULTIPLE" : "LINE_CALL_MODE_SINGLE"; - ast_msg->data = 0; + ast_msg->data = NULL; ast_msg->line = dectmngr_line_to_voicemngr_line(termId); send_event_main(ast_msg, EVENT_MAIN_LINE); } @@ -987,7 +988,7 @@ int ubus_call_asterisk(const struct line_event_t* const ev) struct blob_buf bb; int res; - ENDPT_DBG("ubus call to asterisk, line:%d, event:%s, data:%d\n", ev->line, ev->name, ev->data); + ENDPT_DBG("ubus call to asterisk, line:%d, event:%s, data:%s\n", ev->line, ev->name, ev->data ? ev->data : "<null>"); // Do we know ubus address of Asterisk? if (!asterisk_id) { @@ -998,7 +999,8 @@ int ubus_call_asterisk(const struct line_event_t* const ev) memset(&bb, 0, sizeof(bb)); if (blob_buf_init(&bb, 0)) return -1; blobmsg_add_string(&bb, "event", ev->name); - blobmsg_add_u32(&bb, "data", ev->data); + if (ev->data && *ev->data) + blobmsg_add_string(&bb, "data", ev->data); blobmsg_add_u32(&bb, "line", ev->line); req = calloc(1, sizeof(struct ubus_request)); @@ -1033,10 +1035,6 @@ int ubus_broadcast_event(const struct line_event_t* const ev) struct blob_buf blob; int res = 0; - // Filter out repeated DTMF events - if (strncasecmp(ev->name, "DTMF", strlen("DTMF")) == 0 && ev->data == 1) - return 0; - memset(&blob, 0, sizeof(blob)); if(blob_buf_init(&blob, 0)) return -1;