diff --git a/libvoice/libvoice.h b/libvoice/libvoice.h index 82a15748849baced3d71bd38a00278a6ac78649f..0105e148f850fe75e3e157d7fcde3903ffc181c4 100644 --- a/libvoice/libvoice.h +++ b/libvoice/libvoice.h @@ -19,6 +19,7 @@ #define MIN_CALLER_ID_LEN 14 // Minimum string length to be valid. #define CLID_TIME_DELIM 8 // String index where time record ends. #define CLID_NUMB_REC CLID_TIME_DELIM + 2 // String index where number starts. +#define MAX_CALLER_NAME 60 // Max length of caller's name to be displayed on the DECT handset #define DEBUG_LOOPBACK 0 // Debug - feed received audio back to transmitter diff --git a/line-dect.c b/line-dect.c index 6ea562dfcf07cd44450e425bef62b7a7c259f200..a9c97d47e786806eccad8e6fa6097c091a7e2789 100644 --- a/line-dect.c +++ b/line-dect.c @@ -52,31 +52,32 @@ int ubus_process_queued_reqs_to_dectmngr(void) { if (!req) return 0; - ENDPT_DBG("%s: Poped DECT req %p from list, action: %d pcmId: %d\n", __func__, req, req->action, req->pcm_id); + ENDPT_DBG("%s: Poped DECT req %p from list, action: %d pcmId: %d, caller_id: %s, callerName: %s\n", __func__, req, req->action, + req->pcm_id, req->caller_id, req->caller_name); pcm_states_dump(__func__, req->line); switch (req->action) { case ACTION_CONN_CREATE: case ACTION_SIG_RING: - if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 1, 0, req->caller_id, req->pcm_id, req)) { + if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 1, 0, req->caller_id, req->caller_name, req->pcm_id, req)) { free(req); return -1; } break; case ACTION_CONN_CLOSE: - if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 0, 1, req->caller_id, req->pcm_id, req)) { + if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 0, 1, req->caller_id, req->caller_name, req->pcm_id, req)) { free(req); return -1; } break; case ACTION_SIG_BUSY_TONE: - if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 0, 2, req->caller_id, req->pcm_id, req)) { + if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 0, 2, req->caller_id, req->caller_name, req->pcm_id, req)) { free(req); return -1; } break; case ACTION_SIG_ANSWERED: - if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 2, 0, req->caller_id, req->pcm_id, req)) { + if(ubus_call_dectmngr(voicemngr_line_to_dectmngr_line(req->line), 2, 0, req->caller_id, req->caller_name, req->pcm_id, req)) { free(req); return -1; } diff --git a/line.c b/line.c index 08db84ddb52f053aac6a81d8c2d24485e0ec68a7..0f1e13401b460f852892473bbcd6fbce6c06dd52 100644 --- a/line.c +++ b/line.c @@ -133,6 +133,24 @@ static int dect_tone_play(int line, int pcm, enum VOICE_SIGNAL signal, const cha return 0; } +static void setCallerName(const char *data, char *callerName) +{ + char *start; + + if ( (start = strchr(data,'\"')) ) + { + char *end; + + start += 1; + if ( (end = strchr(start,'\"')) ) + { + int len = ((end - start) < MAX_CALLER_NAME ? (end - start) : MAX_CALLER_NAME); + memcpy(callerName, start, len); + callerName[len] = '\0'; + } + } +} + //---------------------------------------------------------------------------------- // Asterisk wants to make a FXS phone or DECT handset ring probably with a caller ID static int line_signal_ring(int line, int pcm, enum VOICE_SIGNAL signal, const char *data, struct voice_ubus_req_t *ubus_req) @@ -166,6 +184,7 @@ static int line_signal_ring(int line, int pcm, enum VOICE_SIGNAL signal, const c if ((end = strchr(cid_tmp + CLID_NUMB_REC, ',')) != NULL) *end = '\0'; // Find comma after digits and null it strcpy(line_req->caller_id, cid_tmp + CLID_NUMB_REC); // Extract the number + setCallerName(data, line_req->caller_name); } } diff --git a/line.h b/line.h index 3951ab1feb08ef0d6abb8916fd813b20f0d46292..ebef90a92e10f138f7ca247f42a6fb309a80be28 100644 --- a/line.h +++ b/line.h @@ -48,6 +48,7 @@ struct line_req_t { int connection_id; // Connection ID from Asterisk enum line_action_t action; // The requested action from origin char caller_id[MAX_CALLER_ID_LEN]; // Caller ID + char caller_name[MAX_CALLER_NAME]; // Caller Name struct voice_ubus_req_t ubus; }; diff --git a/ubus.c b/ubus.c index 3844f5d995c2eb2adbcccfa512e778ea616babbc..c6efd3053cd49101630771fe6d67524c1f626211 100644 --- a/ubus.c +++ b/ubus.c @@ -76,6 +76,7 @@ enum { 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 }; @@ -176,6 +177,7 @@ static const struct blobmsg_policy request_call_policy[] = { [DECT_ADD] = { .name = "add", .type = BLOBMSG_TYPE_INT32 }, [DECT_REL] = { .name = "release", .type = BLOBMSG_TYPE_INT32 }, [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 }, }; @@ -1061,7 +1063,7 @@ static void got_dectmngr_complete(struct ubus_request *req, int ret __attribute_ // Send a request to dectmngr by calling a remote RPC // method. Don't wait for completion. Instead, when // the invocation finishes, we get "called back". -int ubus_call_dectmngr(int terminal, int add, int release, const char *cid, int pcmId, struct line_req_t *lineReq) +int ubus_call_dectmngr(int terminal, int add, int release, const char *cid, const char *caller_name, int pcmId, struct line_req_t *lineReq) { struct ubus_request *req; struct blob_buf bb; @@ -1083,9 +1085,10 @@ int ubus_call_dectmngr(int terminal, int add, int release, const char *cid, int blobmsg_add_u32(&bb, request_call_policy[DECT_REL].name, release); if(cid && *cid) blobmsg_add_string(&bb, request_call_policy[DECT_CID].name, cid); + if(caller_name && *caller_name) blobmsg_add_string(&bb, request_call_policy[DECT_CALLER_NAME].name, caller_name); blobmsg_add_u32(&bb, request_call_policy[DECT_PCM_ID].name, pcmId); - ENDPT_DBG("Sending ubus request to dectmngr %d %d %d %s %d\n", terminal, add, release, cid, pcmId); + ENDPT_DBG("Sending ubus request to dectmngr %d %d %d %s %s %d\n", terminal, add, release, cid, caller_name, pcmId); req = calloc(1, sizeof(struct ubus_request)); if (!req) { diff --git a/ubus.h b/ubus.h index 3f75034cf2637fe4e672171761844c68d73173c3..a465de6638a6a31e39ace01dc63390e3e2031731 100644 --- a/ubus.h +++ b/ubus.h @@ -14,7 +14,7 @@ int ubus_call_asterisk(const struct line_event_t* const ev); int ubus_broadcast_event(const struct line_event_t* const ev); int send_reply_asterisk(struct voice_ubus_req_t *req, enum ubus_msg_status ubusRet); int send_reply_dectmngr(struct voice_ubus_req_t *req, int terminal, int pcmId, enum ubus_msg_status ubusRet); -int ubus_call_dectmngr(int terminal, int add, int release, const char *cid, int pcmId, struct line_req_t *lineReq); +int ubus_call_dectmngr(int terminal, int add, int release, const char *cid, const char *caller_name, int pcmId, struct line_req_t *lineReq); int perhaps_erase_unused_lines(struct uci_context *context); int config_init(struct uci_context *context, struct uci_package *package); int ubus_disable_receive(void);