From patchwork Sun Apr 21 19:49:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Pigg X-Patchwork-Id: 13637529 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60816446B6 for ; Sun, 21 Apr 2024 19:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728977; cv=none; b=HN0urg+fVDCgQsRq6SET+/qwdKLmsdXzt++RObZ8Ss+49mXvNvFqKZSPvMO6jbgbtEohVyVDSyZInPtp0hbqfFRjV2tc7XPGIJ96BqCNDC8jlvVHg1KB/lbIlq+uITUCyF+UPRTbRpMK43Yj23r3itaIQ7hx5n7xVuzOli36wM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728977; c=relaxed/simple; bh=mdHR//SYPBl1tyzSzHWSfbv1ukU2Lwr0QMVaZgLW2+c=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QO5SPbkaay6uG5+3Ni5rUxxnywvSzsHafe6bq1ddZai9Fxuq9hkyFAHzaYhlWbvlhK5O611TvZnUsVqgbe77BbMyHSp2KFWjMsXqG2zJ8un6Q8OjLbzq53J6ACattoMqNDp2MAgCLAfWvgPIup3hcvN29LvSgj03KhONULdb24g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aJf6fUC1; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aJf6fUC1" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-344047ac7e4so2765202f8f.0 for ; Sun, 21 Apr 2024 12:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713728973; x=1714333773; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=7BH3F6WmB3dIV8eT64QoRVmAkZJFt9RXe+GxxSWfmJE=; b=aJf6fUC1J3hudMr2hB0i7cRz5KWGL3r0ni+2ibWCM5a2sLZ1mWoIavn0cAIDvlTA/a e+PlZAIHSkcs1qxNTwU9jeIhB7MLkyAu4at6PFt57ZCrUm59PdPr76DRqnfd2ZtcCWxB 5rlaTnGY9J/HemGB8aIAwbGE0ctj/4tfwb8nGHN3V2C0udZ0GNYpSXXOUN5u2TshzsQp QzFJvma/xtuSrv09bK6t58uDkRwxfPGsgcg1WflHA/6+zycIHnGRNk6Qaoa98Lp0IGhQ AslU/o+aIbmS9E/TN0LevDhVpObAF2fFV+a8/sSomeQZ6X4rjms4nbLH/6Fkt3JMSmNx 7p5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713728973; x=1714333773; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7BH3F6WmB3dIV8eT64QoRVmAkZJFt9RXe+GxxSWfmJE=; b=pFde/LtG8MA4ytPjLIuvn4TV7rmSLXkd1GRvBPvVos1JizCpyno3Xt3t9LQZ7YASPq xEOL66YP4Q/OgL/wWWY2hsFo25xVs2JORnZRF3rQI57RwSaokwWS/iMVxwkgGRvpi5Oq LnX3hd60B7M3nq69DMTmytcCk/9cXTDql1+MuJoLh4RpZmf7z6d4Ut4SKcR7qcQWpqUq 8fpKVvfXwNm07/vXrq/MzY4J/rpOW1TW7AOf51+aD64Um33b6dDxOAKWTRayXBlsINZO 3DyRoY2Krg0yhlfUOhrXEPhb9A5gSpVV2KoVPrUQEbGQXsxEFaXy/GeH7PBPJN/wnb2C EGRw== X-Gm-Message-State: AOJu0Yw6gaRXUeRxAOfym8Il3HVo3WVK/mlBieWnWozjPBTF/SVlOfiS Tua9c2XsNlAKWgEY0fWFxAN1vC/0/w6yKBlTUDXagDT2ikA8+IFVHv26FQ== X-Google-Smtp-Source: AGHT+IHGncHjqDQ5sCNXArsqYd7cxTTVGFPxZe8VDGvIypsRiJ+82q/pcNQ/1CCBVHCI9sXoSqBZvg== X-Received: by 2002:a05:6000:c8d:b0:34a:7a56:fb3e with SMTP id dp13-20020a0560000c8d00b0034a7a56fb3emr4864355wrb.2.1713728973034; Sun, 21 Apr 2024 12:49:33 -0700 (PDT) Received: from adam-laptop-hp.turtle-stonecat.ts.net ([84.69.230.138]) by smtp.gmail.com with ESMTPSA id n4-20020a5d4844000000b00349f098f4a6sm10018521wrs.53.2024.04.21.12.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 12:49:32 -0700 (PDT) Sender: Adam Pigg From: Adam Pigg To: ofono@lists.linux.dev Cc: Adam Pigg Subject: [PATCH 1/4] qmimodem: voicecall: Implement call dialing Date: Sun, 21 Apr 2024 20:49:03 +0100 Message-ID: <20240421194926.13149-1-adam@piggz.co.uk> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add voicecall dialling to the qmimodem driver Includes required infrastructure and setup of the QMI services Call State Handling =================== On initialisation, register the all_call_status_ind callback to be called for QMI_VOICE_IND_ALL_STATUS. This will handle notification of call status to the rest of the system Dial Handling ============= The dial function sets up the parameters for the QMI_VOICE_DIAL_CALL service. The parameters are the number to be called and the call type, which is currently hard coded to be QMI_VOICE_CALL_TYPE_VOICE. The dial_cb callback will then be called and will receive the call-id. --- Changes in V4 -merged qmi_voice_call_status and all_call_status_ind -several minor structure/formate changes Changes in V5 -renames ofono_call_compare_by_id to ofono_call_match_by_id -updated new_entry pointer to fix use-after-free in ofono_call_list_notify -Renamed several constants -in all_call_status_ind removed error label/gotos after restructuring -When creating the call list, ensure an upper bound of 16 -Fix out-of-mound-read on remote number due to QMI string not being null terminated --- --- drivers/qmimodem/voice.h | 17 ++ drivers/qmimodem/voicecall.c | 426 ++++++++++++++++++++++++++++++++++- 2 files changed, 442 insertions(+), 1 deletion(-) diff --git a/drivers/qmimodem/voice.h b/drivers/qmimodem/voice.h index 917e72f7..2344fd50 100644 --- a/drivers/qmimodem/voice.h +++ b/drivers/qmimodem/voice.h @@ -48,6 +48,9 @@ enum qmi_ussd_user_required { /* QMI service voice. Using an enum to prevent doublicated entries */ enum voice_commands { + QMI_VOICE_DIAL_CALL = 0x20, + QMI_VOICE_ALL_CALL_STATUS_IND = 0x2e, + QMI_VOICE_GET_ALL_CALL_INFO = 0x2f, QMI_VOICE_SUPS_NOTIFICATION_IND = 0x32, QMI_VOICE_SET_SUPS_SERVICE = 0x33, QMI_VOICE_GET_CALL_WAITING = 0x34, @@ -66,6 +69,20 @@ enum voice_commands { QMI_VOICE_GET_CNAP = 0x4d }; +enum qmi_voice_call_state { + QMI_VOICE_CALL_STATE_IDLE = 0x0, + QMI_VOICE_CALL_STATE_ORIG, + QMI_VOICE_CALL_STATE_INCOMING, + QMI_VOICE_CALL_STATE_CONV, + QMI_VOICE_CALL_STATE_CC_IN_PROG, + QMI_VOICE_CALL_STATE_ALERTING, + QMI_VOICE_CALL_STATE_HOLD, + QMI_VOICE_CALL_STATE_WAITING, + QMI_VOICE_CALL_STATE_DISCONNECTING, + QMI_VOICE_CALL_STATE_END, + QMI_VOICE_CALL_STATE_SETUP +}; + struct qmi_ussd_data { uint8_t dcs; uint8_t length; diff --git a/drivers/qmimodem/voicecall.c b/drivers/qmimodem/voicecall.c index aa34fc25..7b4813c9 100644 --- a/drivers/qmimodem/voicecall.c +++ b/drivers/qmimodem/voicecall.c @@ -3,6 +3,7 @@ * oFono - Open Source Telephony * * Copyright (C) 2011-2012 Intel Corporation. All rights reserved. + * Copyright (C) 2024 Adam Pigg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -26,6 +27,10 @@ #include #include #include +#include +#include + +#include "voice.h" #include "qmi.h" @@ -35,8 +40,422 @@ struct voicecall_data { struct qmi_service *voice; uint16_t major; uint16_t minor; + struct l_queue *call_list; + struct ofono_phone_number dialed; }; +struct qmi_voice_call_information_instance { + uint8_t id; + uint8_t state; + uint8_t type; + uint8_t direction; + uint8_t mode; + uint8_t multipart_indicator; + uint8_t als; +} __attribute__((__packed__)); + +struct qmi_voice_call_information { + uint8_t size; + struct qmi_voice_call_information_instance instance[0]; +} __attribute__((__packed__)); + +struct qmi_voice_remote_party_number_instance { + uint8_t call_id; + uint8_t presentation_indicator; + uint8_t number_size; + char number[0]; +} __attribute__((__packed__)); + +struct qmi_voice_remote_party_number { + uint8_t size; + struct qmi_voice_remote_party_number_instance instance[0]; +} __attribute__((__packed__)); + +static int ofono_call_compare(const void *a, const void *b, void *data) +{ + const struct ofono_call *ca = a; + const struct ofono_call *cb = b; + + if (ca->id < cb->id) + return -1; + + if (ca->id > cb->id) + return 1; + + return 0; +} + +static bool ofono_call_match_by_id(const void *a, const void *b) +{ + const struct ofono_call *call = a; + unsigned int id = L_PTR_TO_UINT(b); + + return (call->id == id); +} + +static void ofono_call_list_dial_callback(struct ofono_voicecall *vc, + int call_id) +{ + struct ofono_call *call; + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + struct l_queue *call_list = vd->call_list; + const struct ofono_phone_number *ph = &vd->dialed; + + /* check if call_id already present */ + call = l_queue_find(call_list, ofono_call_match_by_id, + L_UINT_TO_PTR(call_id)); + + if (call) + return; + + call = l_new(struct ofono_call, 1); + call->id = call_id; + + memcpy(&call->called_number, ph, sizeof(*ph)); + call->direction = CALL_DIRECTION_MOBILE_ORIGINATED; + call->status = CALL_STATUS_DIALING; + call->type = 0; /* voice */ + + l_queue_insert(call_list, call, ofono_call_compare, NULL); + + ofono_voicecall_notify(vc, call); +} + +static void ofono_call_list_notify(struct ofono_voicecall *vc, + struct l_queue *calls) +{ + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + struct l_queue *old_calls = vd->call_list; + struct l_queue *new_calls = calls; + struct ofono_call *new_call, *old_call; + const struct l_queue_entry *old_entry, *new_entry; + uint i; + + uint loop_length = + MAX(l_queue_length(old_calls), l_queue_length(new_calls)); + + old_entry = l_queue_get_entries(old_calls); + new_entry = l_queue_get_entries(new_calls); + + for (i = 0; i < loop_length; ++i) { + old_call = old_entry ? old_entry->data : NULL; + new_call = new_entry ? new_entry->data : NULL; + + if (new_call && new_call->status == CALL_STATUS_DISCONNECTED) { + ofono_voicecall_disconnected( + vc, new_call->id, + OFONO_DISCONNECT_REASON_REMOTE_HANGUP, NULL); + new_entry = new_entry->next; + l_queue_remove(calls, new_call); + l_free(new_call); + continue; + } + + if (old_call && + (!new_call || (new_call->id > old_call->id))) + ofono_voicecall_disconnected( + vc, old_call->id, + OFONO_DISCONNECT_REASON_REMOTE_HANGUP, NULL); + else if (new_call && + (!old_call || (new_call->id < old_call->id))) { + DBG("Notify new call %d", new_call->id); + /* new call, signal it */ + if (new_call->type == 0) + ofono_voicecall_notify(vc, new_call); + } else if (memcmp(new_call, old_call, sizeof(*new_call)) && + new_call->type == 0) + ofono_voicecall_notify(vc, new_call); + + if (old_entry) + old_entry = old_entry->next; + if (new_entry) + new_entry = new_entry->next; + } + + l_queue_destroy(old_calls, l_free); + vd->call_list = calls; +} + +static const char *qmi_voice_call_state_name(enum qmi_voice_call_state value) +{ + switch (value) { + case QMI_VOICE_CALL_STATE_IDLE: + return "QMI_VOICE_CALL_STATE_IDLE"; + case QMI_VOICE_CALL_STATE_ORIG: + return "QMI_VOICE_CALL_STATE_ORIG"; + case QMI_VOICE_CALL_STATE_INCOMING: + return "QMI_VOICE_CALL_STATE_INCOMING"; + case QMI_VOICE_CALL_STATE_CONV: + return "QMI_VOICE_CALL_STATE_CONV"; + case QMI_VOICE_CALL_STATE_CC_IN_PROG: + return "QMI_VOICE_CALL_STATE_CC_IN_PROG"; + case QMI_VOICE_CALL_STATE_ALERTING: + return "QMI_VOICE_CALL_STATE_ALERTING"; + case QMI_VOICE_CALL_STATE_HOLD: + return "QMI_VOICE_CALL_STATE_HOLD"; + case QMI_VOICE_CALL_STATE_WAITING: + return "QMI_VOICE_CALL_STATE_WAITING"; + case QMI_VOICE_CALL_STATE_DISCONNECTING: + return "QMI_VOICE_CALL_STATE_DISCONNECTING"; + case QMI_VOICE_CALL_STATE_END: + return "QMI_VOICE_CALL_STATE_END"; + case QMI_VOICE_CALL_STATE_SETUP: + return "QMI_VOICE_CALL_STATE_SETUP"; + } + return "QMI_CALL_STATE_"; +} + +static bool qmi_to_ofono_status(uint8_t status, int *ret) +{ + int err = false; + + switch (status) { + case QMI_VOICE_CALL_STATE_IDLE: + case QMI_VOICE_CALL_STATE_END: + case QMI_VOICE_CALL_STATE_DISCONNECTING: + *ret = CALL_STATUS_DISCONNECTED; + break; + case QMI_VOICE_CALL_STATE_HOLD: + *ret = CALL_STATUS_HELD; + break; + case QMI_VOICE_CALL_STATE_WAITING: + *ret = CALL_STATUS_WAITING; + break; + case QMI_VOICE_CALL_STATE_ORIG: + *ret = CALL_STATUS_DIALING; + break; + case QMI_VOICE_CALL_STATE_SETUP: + case QMI_VOICE_CALL_STATE_INCOMING: + *ret = CALL_STATUS_INCOMING; + break; + case QMI_VOICE_CALL_STATE_CONV: + *ret = CALL_STATUS_ACTIVE; + break; + case QMI_VOICE_CALL_STATE_CC_IN_PROG: + *ret = CALL_STATUS_DIALING; + break; + case QMI_VOICE_CALL_STATE_ALERTING: + *ret = CALL_STATUS_ALERTING; + break; + default: + err = true; + } + return err; +} + +static enum call_direction qmi_to_ofono_direction(uint8_t qmi_direction) +{ + return qmi_direction - 1; +} + +static void all_call_status_ind(struct qmi_result *result, void *user_data) +{ + struct ofono_voicecall *vc = user_data; + + int i; + int offset; + uint16_t len; + bool status = true; + int instance_size; + const struct qmi_voice_call_information *call_information; + const struct qmi_voice_remote_party_number *remote_party_number; + const struct qmi_voice_remote_party_number_instance *remote_party_number_inst[16]; + + static const uint8_t RESULT_CALL_STATUS_CALL_INFORMATION = 0x01; + static const uint8_t RESULT_CALL_STATUS_REMOTE_NUMBER = 0x10; + static const uint8_t RESULT_CALL_INFO_CALL_INFORMATION = 0x10; + static const uint8_t RESULT_CALL_INFO_REMOTE_NUMBER = 0x11; + + DBG(""); + + /* mandatory */ + call_information = qmi_result_get( + result, RESULT_CALL_STATUS_CALL_INFORMATION, &len); + + if (!call_information) { + call_information = qmi_result_get( + result, RESULT_CALL_INFO_CALL_INFORMATION, + &len); + status = false; + } + + if (!call_information || len < sizeof(call_information->size)) { + DBG("Parsing of all call status indication failed"); + return; + } + + if (!call_information->size) { + DBG("No call informations received!"); + return; + } + + if (len != call_information->size * + sizeof(struct qmi_voice_call_information_instance) + + sizeof(call_information->size)) { + DBG("Call information size incorrect"); + return; + } + + /* mandatory */ + remote_party_number = qmi_result_get( + result, + status ? RESULT_CALL_STATUS_REMOTE_NUMBER : + RESULT_CALL_INFO_REMOTE_NUMBER, + &len); + + if (!remote_party_number) { + DBG("Unable to retrieve remote numbers"); + return; + } + + /* verify the length */ + if (len < sizeof(remote_party_number->size)) { + DBG("Parsing of remote numbers failed"); + return; + } + + /* expect we have valid fields for every call */ + if (call_information->size != remote_party_number->size) { + DBG("Not all fields have the same size"); + return; + } + + /* pull the remote call info into a local array */ + instance_size = sizeof(struct qmi_voice_remote_party_number_instance); + + for (i = 0, offset = sizeof(remote_party_number->size); + offset < len && i < 16 && i < remote_party_number->size; + i++) { + const struct qmi_voice_remote_party_number_instance *instance; + + if (offset + instance_size > len) { + DBG("Error parsing remote numbers"); + return; + } + + instance = (void *)remote_party_number + offset; + if (offset + instance_size + instance->number_size > len) { + DBG("Error parsing remote numbers"); + return; + } + + remote_party_number_inst[i] = instance; + offset += + sizeof(struct qmi_voice_remote_party_number_instance) + + instance->number_size; + } + + struct l_queue *calls = l_queue_new(); + + for (i = 0; i < call_information->size && i < 16; i++) { + struct ofono_call *call = l_new(struct ofono_call, 1); + struct qmi_voice_call_information_instance call_info; + const struct qmi_voice_remote_party_number_instance + *remote_party = remote_party_number_inst[i]; + int number_size; + + call_info = call_information->instance[i]; + + call->id = call_info.id; + call->direction = qmi_to_ofono_direction(call_info.direction); + call->type = 0; /* always voice */ + + number_size = MIN(remote_party->number_size, OFONO_MAX_PHONE_NUMBER_LENGTH); + char *tmp = l_strndup(remote_party->number, number_size); + l_strlcpy(call->phone_number.number, tmp, sizeof(call->phone_number.number)); + l_free(tmp); + + if (strlen(call->phone_number.number) > 0) + call->clip_validity = 0; + else + call->clip_validity = 2; + + if (qmi_to_ofono_status(call_info.state, &call->status)) { + DBG("Ignore call id %d, because can not convert QMI state 0x%x to ofono.", + call_info.id, call_info.state); + l_free(call); + continue; + } + + DBG("Call %d in state %s(%d)", call_info.id, + qmi_voice_call_state_name(call_info.state), + call_info.state); + + l_queue_push_tail(calls, call); + } + + ofono_call_list_notify(vc, calls); +} + +static void dial_cb(struct qmi_result *result, void *user_data) +{ + struct cb_data *cbd = user_data; + struct ofono_voicecall *vc = cbd->user; + ofono_voicecall_cb_t cb = cbd->cb; + uint16_t error; + uint8_t call_id; + + static const uint8_t RESULT_CALL_ID = 0x10; + + DBG(""); + + if (qmi_result_set_error(result, &error)) { + DBG("QMI Error %d", error); + CALLBACK_WITH_FAILURE(cb, cbd->data); + return; + } + + if (!qmi_result_get_uint8(result, RESULT_CALL_ID, + &call_id)) { + ofono_error("No call id in dial result"); + CALLBACK_WITH_FAILURE(cb, cbd->data); + return; + } + + DBG("New call QMI id %d", call_id); + ofono_call_list_dial_callback(vc, call_id); + + CALLBACK_WITH_SUCCESS(cb, cbd->data); +} + +static void dial(struct ofono_voicecall *vc, + const struct ofono_phone_number *ph, + enum ofono_clir_option clir, ofono_voicecall_cb_t cb, + void *data) +{ + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + struct cb_data *cbd = cb_data_new(cb, data); + struct qmi_param *param; + const char *calling_number = phone_number_to_string(ph); + + static const uint8_t PARAM_CALL_NUMBER = 0x01; + static const uint8_t PARAM_CALL_TYPE = 0x10; + static const uint8_t QMI_VOICE_CALL_TYPE_VOICE = 0x00; + + DBG(""); + + cbd->user = vc; + memcpy(&vd->dialed, ph, sizeof(*ph)); + + param = qmi_param_new(); + + if (!qmi_param_append(param, PARAM_CALL_NUMBER, + strlen(calling_number), calling_number)) + goto error; + + qmi_param_append_uint8(param, PARAM_CALL_TYPE, + QMI_VOICE_CALL_TYPE_VOICE); + + if (qmi_service_send(vd->voice, QMI_VOICE_DIAL_CALL, param, dial_cb, + cbd, l_free) > 0) + return; + +error: + CALLBACK_WITH_FAILURE(cb, data); + l_free(cbd); + l_free(param); +} + static void create_voice_cb(struct qmi_service *service, void *user_data) { struct ofono_voicecall *vc = user_data; @@ -58,6 +477,9 @@ static void create_voice_cb(struct qmi_service *service, void *user_data) data->voice = qmi_service_ref(service); + qmi_service_register(data->voice, QMI_VOICE_ALL_CALL_STATUS_IND, + all_call_status_ind, vc, NULL); + ofono_voicecall_register(vc); } @@ -70,6 +492,7 @@ static int qmi_voicecall_probe(struct ofono_voicecall *vc, DBG(""); data = l_new(struct voicecall_data, 1); + data->call_list = l_queue_new(); ofono_voicecall_set_data(vc, data); @@ -77,7 +500,6 @@ static int qmi_voicecall_probe(struct ofono_voicecall *vc, create_voice_cb, vc, NULL); return 0; - } static void qmi_voicecall_remove(struct ofono_voicecall *vc) @@ -92,12 +514,14 @@ static void qmi_voicecall_remove(struct ofono_voicecall *vc) qmi_service_unref(data->voice); + l_queue_destroy(data->call_list, l_free); l_free(data); } static const struct ofono_voicecall_driver driver = { .probe = qmi_voicecall_probe, .remove = qmi_voicecall_remove, + .dial = dial, }; OFONO_ATOM_DRIVER_BUILTIN(voicecall, qmimodem, &driver) From patchwork Sun Apr 21 19:49:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Pigg X-Patchwork-Id: 13637530 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 917C7111AD for ; Sun, 21 Apr 2024 19:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728979; cv=none; b=qyBAYRYeLxcYBpCgsW7seHs6hP1fvrvGjTUihCo8ezp3xCfGU3htkFpr5QtDR6GFcMiR0YHpImi4yaqsboWx9AL3tO40ozS0aLunRvBb5G9ZMRfTyRiQBbmzexaE8biF5e8CL05OmE5VtAUEFt2fb8EXwIURvr55VMqeSFXFogE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728979; c=relaxed/simple; bh=3iArTPF19gocDR2k/+lng0eVon0ueRmbh9OB9ZtnTks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tWnZPaky/cwzJYWrWsZIEWvIDfjIoNy1RMg8SW55/mSra/bTCsMR+GLNXDviY5BDyma2Ha1alq6MBpqFIrPjMEedQ3LR+rIYhHlHo3s+JHA0h6CC3GJDyXIe31fBYk73XQEeoD9xeikAT+ys5aBK0dcpuyX8FVS1kHmoLGJGUE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NQcWDG9i; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NQcWDG9i" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-34a7e47d164so1811884f8f.3 for ; Sun, 21 Apr 2024 12:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713728975; x=1714333775; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=ad34TCKw/ZYYmRxVlUipABIPNiBIVoMbj9jd5/glJ8M=; b=NQcWDG9iSKSElgjnyQeV1IwyvtIuCmcmlwbLoWyrqBye6LhMyVtn2NaYfTr5kEJHww Rneso4UwQgf/I2yhrZMhDPFHbrcBDRqPYoNSFR4OLsUP+Q2n7q7GuSArRGw4Aew9mAAJ cVU4KU9+Pj0p0SSxqWAUbfT4pCeRVJYt6YGjoRWN/v34/DDqR5FR/8vmc9a51FqLFqxQ iGM+L/KaaLHgSQP57hNiLBrxjEw5rbcHxumK5nt7I15atsKYArjkHyETpeGM1PC/FOWi V60fZHe1fyycJIkau0vY4xovBSDRTJHRg2qRUOyFJwSIXLOVgjpA9LHRw26zQwLrtUlA fqLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713728975; x=1714333775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ad34TCKw/ZYYmRxVlUipABIPNiBIVoMbj9jd5/glJ8M=; b=Vul4OTWkH2MQXexPMm/hvliDdfjVrgM1eKBg95V7a7pMPyS6SdzhmTUP28iNY7m5md LP21DMJDCESFdK+2Yc601J9zjN01cnas0th1qDSkfAiYfR8CjedpvEXUdlaqlOg6Thqg wQ5muHMf9bo5HvdrNVAJOISlrcLdMeEc1ogZdHJ8i2tJeg+WaRi1FvkmuHAGR+QV5yfw 1tNd2bKcfsjdLMqNTBJhw2bUbdenbtc3p/iGHGzAYbyMlofOv0mpPmS2Lfr8pFgweW/a wBURxAcUwK8BWxr5qRwMTCHHKL1kGVBlerxblkhdl7M2dwwgh7gOkdx3O46JyST4jMkb /bzg== X-Gm-Message-State: AOJu0YwikYb6LDzHi1IgREHTOyneazEQDdYqL7VOSXF0xVJF9MD1mML+ Qaiaz3h8kmgQBA4VDDxyaby58tokL800Nki3wu8aJtFzH2WHrHc8Ffjkbg== X-Google-Smtp-Source: AGHT+IFf+me1pDShaNZXxTUjmsHNCtv8V1SUx3vdQBTgkTVQpwYyy9PCAB4kSLGjsvjki2SA4kFXGw== X-Received: by 2002:a5d:52c7:0:b0:34a:3bbc:a4b5 with SMTP id r7-20020a5d52c7000000b0034a3bbca4b5mr4822619wrv.70.1713728975248; Sun, 21 Apr 2024 12:49:35 -0700 (PDT) Received: from adam-laptop-hp.turtle-stonecat.ts.net ([84.69.230.138]) by smtp.gmail.com with ESMTPSA id n4-20020a5d4844000000b00349f098f4a6sm10018521wrs.53.2024.04.21.12.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 12:49:34 -0700 (PDT) Sender: Adam Pigg From: Adam Pigg To: ofono@lists.linux.dev Cc: Adam Pigg Subject: [PATCH 2/4] qmimodem: voicecall: Implement call answer Date: Sun, 21 Apr 2024 20:49:04 +0100 Message-ID: <20240421194926.13149-2-adam@piggz.co.uk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240421194926.13149-1-adam@piggz.co.uk> References: <20240421194926.13149-1-adam@piggz.co.uk> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The answer function setup the parameters for a call to the service function QMI_VOICE_ANSWER_CALL. The only parameter is the call-id. answer_cb will then be called which retrieves the call-id and checks the status of the result. --- Changes in V4 -Minor rework to the answer function Changes in V5 -Renamed ofono_call_compare_by_status ofono_call_match_by_status -Renamed parameters -Made answer() ofono_error if call is null --- --- drivers/qmimodem/voice.h | 1 + drivers/qmimodem/voicecall.c | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/drivers/qmimodem/voice.h b/drivers/qmimodem/voice.h index 2344fd50..a524cf98 100644 --- a/drivers/qmimodem/voice.h +++ b/drivers/qmimodem/voice.h @@ -51,6 +51,7 @@ enum voice_commands { QMI_VOICE_DIAL_CALL = 0x20, QMI_VOICE_ALL_CALL_STATUS_IND = 0x2e, QMI_VOICE_GET_ALL_CALL_INFO = 0x2f, + QMI_VOICE_ANSWER_CALL = 0x22, QMI_VOICE_SUPS_NOTIFICATION_IND = 0x32, QMI_VOICE_SET_SUPS_SERVICE = 0x33, QMI_VOICE_GET_CALL_WAITING = 0x34, diff --git a/drivers/qmimodem/voicecall.c b/drivers/qmimodem/voicecall.c index 7b4813c9..99ec97f9 100644 --- a/drivers/qmimodem/voicecall.c +++ b/drivers/qmimodem/voicecall.c @@ -93,6 +93,14 @@ static bool ofono_call_match_by_id(const void *a, const void *b) return (call->id == id); } +static bool ofono_call_match_by_status(const void *a, const void *b) +{ + const struct ofono_call *call = a; + int status = L_PTR_TO_INT(b); + + return status == call->status; +} + static void ofono_call_list_dial_callback(struct ofono_voicecall *vc, int call_id) { @@ -456,6 +464,67 @@ error: l_free(param); } +static void answer_cb(struct qmi_result *result, void *user_data) +{ + struct cb_data *cbd = user_data; + ofono_voicecall_cb_t cb = cbd->cb; + uint16_t error; + uint8_t call_id; + + static const uint8_t RESULT_CALL_ID = 0x10; + + DBG(""); + + if (qmi_result_set_error(result, &error)) { + DBG("QMI Error %d", error); + CALLBACK_WITH_FAILURE(cb, cbd->data); + return; + } + + if (qmi_result_get_uint8(result, RESULT_CALL_ID, &call_id)) + DBG("Received answer result with call id %d", call_id); + + CALLBACK_WITH_SUCCESS(cb, cbd->data); +} + +static void answer(struct ofono_voicecall *vc, ofono_voicecall_cb_t cb, void *data) +{ + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + struct cb_data *cbd; + struct ofono_call *call; + struct qmi_param *param = NULL; + + static const uint8_t PARAM_CALL_ID = 0x01; + + DBG(""); + + call = l_queue_find(vd->call_list, + ofono_call_match_by_status, + L_UINT_TO_PTR(CALL_STATUS_INCOMING)); + + param = qmi_param_new(); + cbd = cb_data_new(cb, data); + cbd->user = vc; + + if (call == NULL) { + ofono_error("Can not find a call to pick up"); + goto error; + } + + if (!qmi_param_append_uint8(param, PARAM_CALL_ID, + call->id)) + goto error; + + if (qmi_service_send(vd->voice, QMI_VOICE_ANSWER_CALL, param, + answer_cb, cbd, l_free) > 0) + return; + +error: + CALLBACK_WITH_FAILURE(cb, data); + l_free(cbd); + l_free(param); +} + static void create_voice_cb(struct qmi_service *service, void *user_data) { struct ofono_voicecall *vc = user_data; @@ -522,6 +591,7 @@ static const struct ofono_voicecall_driver driver = { .probe = qmi_voicecall_probe, .remove = qmi_voicecall_remove, .dial = dial, + .answer = answer, }; OFONO_ATOM_DRIVER_BUILTIN(voicecall, qmimodem, &driver) From patchwork Sun Apr 21 19:49:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Pigg X-Patchwork-Id: 13637531 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60D573FE4B for ; Sun, 21 Apr 2024 19:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728982; cv=none; b=IH5FJB3wQJZ7fdJnyJNgzcH9R5x94WWADQPahx8dGQvX9tzAGB2SycSWkkPSBkxjrRK2aSyT/2iovFsJ1LdQbYW0+ilcCHeR8NnWFLxgsBWyHlrWRHN0fT/9ntHU/n+QxJlmRFihQwnszlWZ6ZAYaav7nACnVTl08GuiWRHTA/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728982; c=relaxed/simple; bh=yD7O7W31T+2kKAV3E52LsNbxhQvSeMKBQE9N5O6hb/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AqQRKZvjo+R9O1RmVr9yVRcZl8CnTZSOHyWFe8wiimpPr24fDk+V95jwCScuUcIrKTihRnWYdjUcSbO590bRK8gcueM/a8kWdcLKvqE9SjXDyRZAt2Q1ZdiiRLSn1jsSwcSc/0h9Lr8/x53XeXwJ1bDQrVV4DnJGweYWj3EZY1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mOqDQZFF; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mOqDQZFF" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-41a69327d3eso425415e9.0 for ; Sun, 21 Apr 2024 12:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713728978; x=1714333778; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+24qO9MC3teApNenS+4Mxyv0XGd0Q8G4MSGgs2+p9uI=; b=mOqDQZFFxzhOwKoa/SoRcceahAAk3X9/AGfUGUiu0HmZ6cLqQh39/3MgeHCq6HBZwe lPEEc55sufFavkSuBInrHJTYbFFnBkrdQd1PF35tJFl+WXM3jNR7srECQgrdF+cl+Lbd Be0xPpIDHI7ubGSSIFXnWzeACTM75NhYfw8USqoemzETsoGNVUDi2SA1XeruhxafvZvh VpuBBLu3+F/WR9TH2T/FHGXq24bLxwVK/BTiqsa+pCdeZNwiDBr8N5VQ0SRWzz0ebyaw lLPX/ZOXUm7rzTl4+JG4BsHT0TZ9TuYFVvksyQajxWWHHoPt0PBp6A5AxkfMTbhkFeXp LGuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713728978; x=1714333778; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+24qO9MC3teApNenS+4Mxyv0XGd0Q8G4MSGgs2+p9uI=; b=BbXzooTyAaq5rto0RTcDvgW0AiT3p/1wFwPsSMgnhhKPVVXPSHacqtBAciDDI+qbxN 48HU6EwirZdd4Xj7WAfXK672eo+w317nxU+ToPK7OIh4yKr9Z9rxgEKno8t9l8Ea8o9v t6UY+igtSeSDHtwH5oC6rzTbn+cdKpz3KGF5+J5ZSYgmhEefcAFQPj+XI8E2ww/lsEvo QWfLhGtecwPaZCLAxJMo/AZ+veIP/QgUZkcxSZ5wlJLrmUUYHiWV0AtwkOYKUa17dlu9 6sx8+raoNhbzVvQqdpKwu7Fg0ULpUx86aGv15/JZeCGkMZozBl3n38wQVs6JwpKIk+6J 6iSg== X-Gm-Message-State: AOJu0YzpqsTnNMHJ2rrhRK51v5z5Yq2xLYEpu7dBAM764uEnG6Viprnv fQf8vGXxYPaBgK4+nNJVybC1OhYKFLSc9mU7gYdA+rgcSx+Eh0rvwOZz1Q== X-Google-Smtp-Source: AGHT+IHBOKwSOYnUQlIP+bgaMOw/XqheN0gc3THkgMfTugW5Izxk9RZRG7CwP7ln8oaFvUSO7yLHpg== X-Received: by 2002:adf:e84b:0:b0:348:3fa4:21f8 with SMTP id d11-20020adfe84b000000b003483fa421f8mr6668389wrn.15.1713728978035; Sun, 21 Apr 2024 12:49:38 -0700 (PDT) Received: from adam-laptop-hp.turtle-stonecat.ts.net ([84.69.230.138]) by smtp.gmail.com with ESMTPSA id n4-20020a5d4844000000b00349f098f4a6sm10018521wrs.53.2024.04.21.12.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 12:49:37 -0700 (PDT) Sender: Adam Pigg From: Adam Pigg To: ofono@lists.linux.dev Cc: Adam Pigg Subject: [PATCH 3/4] qmimodem: voicecall: Implement active call hangup Date: Sun, 21 Apr 2024 20:49:05 +0100 Message-ID: <20240421194926.13149-3-adam@piggz.co.uk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240421194926.13149-1-adam@piggz.co.uk> References: <20240421194926.13149-1-adam@piggz.co.uk> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 hangup_active iterates the current list of calls, looking for the first active call and then calls release_specific. This then sets up the parameters for a call to QMI_VOICE_END_CALL, with the only parameters being the call-id. end_call_cb will then be called and will parse out the call-id and check for success. --- Changes in V4 -Minor rework to hangup_active -Removed unnescessary changes Changes in V5 -Renamed parameters --- --- drivers/qmimodem/voice.h | 1 + drivers/qmimodem/voicecall.c | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/drivers/qmimodem/voice.h b/drivers/qmimodem/voice.h index a524cf98..caedb079 100644 --- a/drivers/qmimodem/voice.h +++ b/drivers/qmimodem/voice.h @@ -51,6 +51,7 @@ enum voice_commands { QMI_VOICE_DIAL_CALL = 0x20, QMI_VOICE_ALL_CALL_STATUS_IND = 0x2e, QMI_VOICE_GET_ALL_CALL_INFO = 0x2f, + QMI_VOICE_END_CALL = 0x21, QMI_VOICE_ANSWER_CALL = 0x22, QMI_VOICE_SUPS_NOTIFICATION_IND = 0x32, QMI_VOICE_SET_SUPS_SERVICE = 0x33, diff --git a/drivers/qmimodem/voicecall.c b/drivers/qmimodem/voicecall.c index 99ec97f9..6b80f576 100644 --- a/drivers/qmimodem/voicecall.c +++ b/drivers/qmimodem/voicecall.c @@ -525,6 +525,86 @@ error: l_free(param); } +static void end_call_cb(struct qmi_result *result, void *user_data) +{ + struct cb_data *cbd = user_data; + ofono_voicecall_cb_t cb = cbd->cb; + uint16_t error; + uint8_t call_id; + + static const uint8_t RESULT_CALL_ID = 0x10; + + if (qmi_result_set_error(result, &error)) { + DBG("QMI Error %d", error); + CALLBACK_WITH_FAILURE(cb, cbd->data); + return; + } + + if (qmi_result_get_uint8(result, RESULT_CALL_ID, &call_id)) + DBG("Received end call result with call id %d", call_id); + + CALLBACK_WITH_SUCCESS(cb, cbd->data); +} + +static void release_specific(struct ofono_voicecall *vc, int id, + ofono_voicecall_cb_t cb, void *data) +{ + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + struct cb_data *cbd; + struct qmi_param *param = NULL; + + static const uint8_t PARAM_CALL_ID = 0x01; + + DBG(""); + + param = qmi_param_new(); + cbd = cb_data_new(cb, data); + cbd->user = vc; + + if (!qmi_param_append_uint8(param, PARAM_CALL_ID, id)) + goto error; + + if (qmi_service_send(vd->voice, QMI_VOICE_END_CALL, param, end_call_cb, + cbd, l_free) > 0) + return; + +error: + CALLBACK_WITH_FAILURE(cb, data); + l_free(cbd); + l_free(param); +} + +static void hangup_active(struct ofono_voicecall *vc, ofono_voicecall_cb_t cb, + void *data) +{ + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + struct ofono_call *call; + enum call_status active[] = { + CALL_STATUS_ACTIVE, + CALL_STATUS_DIALING, + CALL_STATUS_ALERTING, + CALL_STATUS_INCOMING, + }; + + DBG(""); + + for (uint32_t i = 0; i < L_ARRAY_SIZE(active); i++) { + call = l_queue_find(vd->call_list, ofono_call_match_by_status, + L_INT_TO_PTR(active[i])); + + if (call) + break; + } + + if (call == NULL) { + DBG("Can not find a call to hang up"); + CALLBACK_WITH_FAILURE(cb, data); + return; + } + + release_specific(vc, call->id, cb, data); +} + static void create_voice_cb(struct qmi_service *service, void *user_data) { struct ofono_voicecall *vc = user_data; @@ -592,6 +672,8 @@ static const struct ofono_voicecall_driver driver = { .remove = qmi_voicecall_remove, .dial = dial, .answer = answer, + .hangup_active = hangup_active, + .release_specific = release_specific, }; OFONO_ATOM_DRIVER_BUILTIN(voicecall, qmimodem, &driver) From patchwork Sun Apr 21 19:49:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Pigg X-Patchwork-Id: 13637532 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 239E6111AD for ; Sun, 21 Apr 2024 19:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728983; cv=none; b=lnX5wiOcz/vzuU/chEztsRzDkrLN4svtzOGXHUyTTwR7T9ntzz8puT0Go2c4m4F7ADS/x3iyf6HLovMsEZn/cYGIcPhGPOFwvPyQKD4Ib6mjXzJnDvLtK+SW0hg1hbXcTjZuPg7kxzbiJudmOf1/JjnbBcIc+DSU160BzkJyBV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728983; c=relaxed/simple; bh=EXRVrXzOTtHanjNl+8DcPp3jW7YCkVIX0/+JiUBZmQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sOxG5GKy0LY7HK3ElQG61ZSdjB1e/KuHtcLxzUmAp73WYrNNaWSfru1Vts41ypPAFfBgtSC6FPkXMICYa9wrpO6DzRdpCeootgyQOPBDhHhbRYNc3UQ5rC9igYe+MLRYFVnwEaqAjNUt8UG/qKsOL6Uh+dCeY1VmNooNGh6GlmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=glayFZwb; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=piggz.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="glayFZwb" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3465921600dso3286013f8f.3 for ; Sun, 21 Apr 2024 12:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713728980; x=1714333780; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=iBA/w4e9EGprRO54+H1zZnnD6BoS3h9gx6NZ4XvKCV4=; b=glayFZwbtasYLs+Il/DEsRJeAuaWim8sx0xBx1wsbK0K8YNaA8ybB3JBvIXxQ9XAjN ZzWP2Agyooq5jguNHII3N+dyEeyw04XP8HCW5KR0vzt2O77KtFK7Og8dXg2gQacDF/k5 VooUt3ao6N5frtHoFw1CsBb2mjsJfPMjCsETWDL7ELjUfPntKnwXUebnYsYmIWlUKPGf PAJZYpJoPCq5Cv7s83c8dLuLxvrE2X8bTC4vHRVR5mFCNtlhL11qtz8AJzK6QdpbYZ58 ItH/HrnqGXHFrN1b7QTW77lBNr4YKo+4DPUcs6+clNcy81GPBikiMJ+ScD2HIZv2ylLu OCpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713728980; x=1714333780; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iBA/w4e9EGprRO54+H1zZnnD6BoS3h9gx6NZ4XvKCV4=; b=tYUeUWDwHm39SGRlkGh/KBs0VicwTfItSpdZm6UkdNSeNbTWpf0WHyA93No/H3oTq6 I+PJiQZ4yWVgspdOjBK7EB68v0XqDKB5a3638ixflHHKTg3FGfJnZx7lhykgcfGyQnPc mjGF8uibu3v4Q12E6lcAI5pfzwLLYfDhwd1Es+Q7DAkxtJwRfLSFRmXjI70+mQ0QsTv6 rXl+BdCgRBhtnDm3c0yrlvUOLh2nsgSNxvL6PL39oOrUmjE3BvZgN3F3gt6DPiR67OJw XUo9ADBu65DGVaXkNFdyD2O8KTvfkiAfs5ka6Zo1yG/JYVY3yI6nwDy/DaRDsXxh9HzM ZDzA== X-Gm-Message-State: AOJu0YzhYdjfqiwUcsdAbWgpl6YoDjNuYyAGC/bNSEuU8hdg1UwcN1ir JtOtRZoIDdEAf4sYAEVmM/+BPlN7ytKEK2a8FxD31sMPxIW7aa+0twSUOw== X-Google-Smtp-Source: AGHT+IHYog/UIqyFB8ZF6KRDH6peOcJ6EtF36n4NISXpbwBXjg6QnYkdLp80WIZdOGYJookO9QhhGg== X-Received: by 2002:adf:ff8e:0:b0:34a:56e7:5cc4 with SMTP id j14-20020adfff8e000000b0034a56e75cc4mr5399916wrr.2.1713728980202; Sun, 21 Apr 2024 12:49:40 -0700 (PDT) Received: from adam-laptop-hp.turtle-stonecat.ts.net ([84.69.230.138]) by smtp.gmail.com with ESMTPSA id n4-20020a5d4844000000b00349f098f4a6sm10018521wrs.53.2024.04.21.12.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 12:49:39 -0700 (PDT) Sender: Adam Pigg From: Adam Pigg To: ofono@lists.linux.dev Cc: Adam Pigg Subject: [PATCH 4/4] qmimodem: voicecall: Implement DTMF tones Date: Sun, 21 Apr 2024 20:49:06 +0100 Message-ID: <20240421194926.13149-4-adam@piggz.co.uk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240421194926.13149-1-adam@piggz.co.uk> References: <20240421194926.13149-1-adam@piggz.co.uk> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The send_dtmf function sets up a call to send_one_dtmf, which will call the QMI_VOICE_START_CONTINUOUS_DTMF service function. The parameters to this call are a hard coded call-id and the DTMF character to send. start_cont_dtmf_cb will then be called which will set up a call to QMI_VOICE_STOP_CONTINUOUS_DTMF to stop the tone. Finally, stop_cont_dtmf_cb will check the final status. --- Changes in V4 -Removed unused enum -Minor formatting fixes -Ensure data->full_dtmf is free'd -Use cb_data_ref/unref between chains of dtmf calls Changes in V5 -Store the cb and cbd obejects in the voicall_data struct --- --- drivers/qmimodem/voice.h | 6 ++ drivers/qmimodem/voicecall.c | 114 +++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/drivers/qmimodem/voice.h b/drivers/qmimodem/voice.h index caedb079..961fe19f 100644 --- a/drivers/qmimodem/voice.h +++ b/drivers/qmimodem/voice.h @@ -53,6 +53,8 @@ enum voice_commands { QMI_VOICE_GET_ALL_CALL_INFO = 0x2f, QMI_VOICE_END_CALL = 0x21, QMI_VOICE_ANSWER_CALL = 0x22, + QMI_VOICE_START_CONTINUOUS_DTMF = 0x29, + QMI_VOICE_STOP_CONTINUOUS_DTMF = 0x2A, QMI_VOICE_SUPS_NOTIFICATION_IND = 0x32, QMI_VOICE_SET_SUPS_SERVICE = 0x33, QMI_VOICE_GET_CALL_WAITING = 0x34, @@ -85,6 +87,10 @@ enum qmi_voice_call_state { QMI_VOICE_CALL_STATE_SETUP }; +enum qmi_voice_call_dtmf_param { + QMI_VOICE_DTMF_DATA = 0x01, +}; + struct qmi_ussd_data { uint8_t dcs; uint8_t length; diff --git a/drivers/qmimodem/voicecall.c b/drivers/qmimodem/voicecall.c index 6b80f576..f51452e5 100644 --- a/drivers/qmimodem/voicecall.c +++ b/drivers/qmimodem/voicecall.c @@ -42,6 +42,10 @@ struct voicecall_data { uint16_t minor; struct l_queue *call_list; struct ofono_phone_number dialed; + char *full_dtmf; + const char *next_dtmf; + ofono_voicecall_cb_t send_dtmf_cb; + struct cb_data *send_dtmf_data; }; struct qmi_voice_call_information_instance { @@ -605,6 +609,114 @@ static void hangup_active(struct ofono_voicecall *vc, ofono_voicecall_cb_t cb, release_specific(vc, call->id, cb, data); } +static void stop_cont_dtmf_cb(struct qmi_result *result, void *user_data) +{ + struct voicecall_data *vd = user_data; + uint16_t error; + + DBG(""); + + if (qmi_result_set_error(result, &error)) { + DBG("QMI Error %d", error); + CALLBACK_WITH_FAILURE(vd->send_dtmf_cb, vd->send_dtmf_data); + return; + } + + CALLBACK_WITH_SUCCESS(vd->send_dtmf_cb, vd->send_dtmf_data); +} + +static void start_cont_dtmf_cb(struct qmi_result *result, void *user_data) +{ + struct voicecall_data *vd = user_data; + uint16_t error; + struct qmi_param *param; + + DBG(""); + + param = qmi_param_new(); + + if (qmi_result_set_error(result, &error)) + goto error; + + if (!qmi_param_append_uint8(param, QMI_VOICE_DTMF_DATA, 0xff)) + goto error; + + if (qmi_service_send(vd->voice, QMI_VOICE_STOP_CONTINUOUS_DTMF, param, + stop_cont_dtmf_cb, vd, NULL) > 0) + return; + +error: + CALLBACK_WITH_FAILURE(vd->send_dtmf_cb, vd->send_dtmf_data); + l_free(param); +} + +static void send_one_dtmf(struct ofono_voicecall *vc, const char dtmf, + ofono_voicecall_cb_t cb, void *data) +{ + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + struct qmi_param *param = NULL; + uint8_t param_body[2]; + + DBG(""); + + param = qmi_param_new(); + + param_body[0] = 0xff; + param_body[1] = (uint8_t)dtmf; + + if (!qmi_param_append(param, QMI_VOICE_DTMF_DATA, sizeof(param_body), + param_body)) + goto error; + + if (qmi_service_send(vd->voice, QMI_VOICE_START_CONTINUOUS_DTMF, param, + start_cont_dtmf_cb, vd, NULL) > 0) + return; + +error: + CALLBACK_WITH_FAILURE(cb, data); + l_free(param); +} + +static void send_one_dtmf_cb(const struct ofono_error *error, void *data) +{ + struct cb_data *cbd = data; + struct voicecall_data *vd = ofono_voicecall_get_data(cbd->user); + ofono_voicecall_cb_t cb = vd->send_dtmf_cb; + + DBG(""); + + if (error->type != OFONO_ERROR_TYPE_NO_ERROR || + *vd->next_dtmf == 0) { + if (error->type == OFONO_ERROR_TYPE_NO_ERROR) + CALLBACK_WITH_SUCCESS(cb, cbd->data); + else + CALLBACK_WITH_FAILURE(cb, cbd->data); + + l_free(vd->full_dtmf); + vd->full_dtmf = NULL; + } else + send_one_dtmf(cbd->user, + *(vd->next_dtmf++), + send_one_dtmf_cb, vd->send_dtmf_data); +} + +static void send_dtmf(struct ofono_voicecall *vc, const char *dtmf, + ofono_voicecall_cb_t cb, void *data) +{ + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + + DBG(""); + + l_free(vd->full_dtmf); + vd->full_dtmf = l_strdup(dtmf); + vd->next_dtmf = &vd->full_dtmf[1]; + + vd->send_dtmf_data = data; + vd->send_dtmf_cb = cb; + + send_one_dtmf(vc, *dtmf, send_one_dtmf_cb, NULL); +} + static void create_voice_cb(struct qmi_service *service, void *user_data) { struct ofono_voicecall *vc = user_data; @@ -664,6 +776,7 @@ static void qmi_voicecall_remove(struct ofono_voicecall *vc) qmi_service_unref(data->voice); l_queue_destroy(data->call_list, l_free); + l_free(data->full_dtmf); l_free(data); } @@ -674,6 +787,7 @@ static const struct ofono_voicecall_driver driver = { .answer = answer, .hangup_active = hangup_active, .release_specific = release_specific, + .send_tones = send_dtmf, }; OFONO_ATOM_DRIVER_BUILTIN(voicecall, qmimodem, &driver)