From d60ec7649f2914d11c7937eed809b2720afb02a8 Mon Sep 17 00:00:00 2001 From: Yalu Zhang <yalu.zhang@iopsys.eu> Date: Tue, 15 Apr 2025 15:47:57 +0200 Subject: [PATCH] Add parameter data in ubus call from dectmngr --- libvoice/libvoice.h | 2 ++ line.c | 10 +++++++-- line.h | 2 +- ubus.c | 53 +++++++++++++++++++++++---------------------- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/libvoice/libvoice.h b/libvoice/libvoice.h index 5cbc222..b42014e 100644 --- a/libvoice/libvoice.h +++ b/libvoice/libvoice.h @@ -142,6 +142,8 @@ struct line_t { uint16_t conference_started; // True if conference has just been setup by DECT handset int pcm_callid[2]; // -1: Invalid, 0: Obtaining, >0: Established pe_list_t *pending_digits; // List of keypad digits waiting to be sent +#define VOICEMNGR_LINE_FLAG_NARROW_BAND_ONLY 0x1 + uint32_t flags; void *priv; // Platform dependent data }; diff --git a/line.c b/line.c index 08769af..4c69f54 100644 --- a/line.c +++ b/line.c @@ -590,14 +590,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 (pcm == PCM_0 || pcm == PCM_1) { @@ -606,6 +606,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 { diff --git a/line.h b/line.h index c1b783a..e1118c8 100644 --- a/line.h +++ b/line.h @@ -58,7 +58,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/ubus.c b/ubus.c index 27cfcae..4b2df01 100644 --- a/ubus.c +++ b/ubus.c @@ -51,34 +51,35 @@ enum { __RTP_STATS_MAX, }; -enum { // Line config enums - LINE_NAME, // Line name as in GUI - LINE_NOISE, // Comfort nose - LINE_ECHO, // Echo cancelation - LINE_ID, // Iopsys ID of line - LINE_SILENCE, // Silence suppression +enum { // Line config enums + LINE_NAME, // Line name as in GUI + LINE_NOISE, // Comfort nose + LINE_ECHO, // Echo cancelation + LINE_ID, // Iopsys ID of line + LINE_SILENCE, // Silence suppression LINE_TXGAIN, LINE_RXGAIN, }; enum { - UCI_REPLY_STRING, // UBUS reply consisting of one single string - UCI_REPLY_TABLE, // UBUS reply consisting of a subtable + UCI_REPLY_STRING, // UBUS reply consisting of one single string + UCI_REPLY_TABLE, // UBUS reply consisting of a subtable }; // New ubus objects in global context enum { - OBJ_ID, // UBUS ID of object - OBJ_PATH, // String path of object + OBJ_ID, // UBUS ID of object + OBJ_PATH, // String path of object }; enum { - DECT_TERM, // Terminal ID - DECT_ADD, // Add call using PCMx - DECT_REL, // Release call using PCMx - DECT_CID, // Caller ID - DECT_CALLER_NAME, // Caller Name - DECT_PCM_ID, // PCM ID + DECT_TERM, // Terminal ID + DECT_ADD, // Add call using PCMx + DECT_REL, // Release call using PCMx + DECT_CID, // Caller ID + DECT_CALLER_NAME, // Caller Name + 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. @@ -183,6 +184,7 @@ static const struct blobmsg_policy request_call_policy[] = { [DECT_CID] = { .name = "cid", .type = BLOBMSG_TYPE_STRING }, [DECT_CALLER_NAME] = { .name = "caller_name", .type = BLOBMSG_TYPE_STRING }, [DECT_PCM_ID] = { .name = "pcm_id", .type = BLOBMSG_TYPE_INT32 }, + [DECT_DATA] = { .name = "data", .type = BLOBMSG_TYPE_STRING }, }; // Our ubus RPC methods @@ -889,15 +891,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), @@ -927,7 +923,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) { @@ -947,7 +948,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; } -- GitLab