Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tapi #9

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ if(CONFIG_TELEPHONY)
set(CSRCS)
file(GLOB APPEND_FILES ${CMAKE_CURRENT_LIST_DIR}/src/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(REMOVE_ITEM CSRCS ${CMAKE_CURRENT_LIST_DIR}/tools/telephony_tool.c)
set(INCDIR
${NUTTX_APPS_DIR}/external/dbus/dbus
${NUTTX_APPS_DIR}/external/ofono/include
Expand All @@ -49,6 +48,36 @@ if(CONFIG_TELEPHONY)
tapi)
endif()

if(CONFIG_TELEPHONY_TEST)
file(GLOB APPEND_FILES ${CMAKE_CURRENT_LIST_DIR}/test/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(REMOVE_ITEM CSRCS ${CMAKE_CURRENT_LIST_DIR}/test/cmocka_telephony_test.c
${CMAKE_CURRENT_LIST_DIR}/test/product_telephony_test.c)
set(MAINSRC)

if(CONFIG_GOLDFISH_RIL)
list(APPEND MAINSRC test/cmocka_telephony_test.c)
else()
list(APPEND MAINSRC test/product_telephony_test.c)
endif()

nuttx_add_application(
MODULE
${CONFIG_TELEPHONY_TEST}
NAME
cmocka_telephony_test
STACKSIZE
${CONFIG_TELEPHONY_TEST_STACKSIZE}
PRIORITY
${CONFIG_TELEPHONY_TEST_PRIORITY}
SRCS
${MAINSRC}
INCLUDE_DIRECTORIES
${INCDIR}
DEPENDS
tapi cmocka)
endif()

target_include_directories(tapi PRIVATE ${INCDIR})
target_sources(tapi PRIVATE ${CSRCS})
endif()
4 changes: 1 addition & 3 deletions src/tapi_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ static void deflect_param_append_0(DBusMessageIter* iter, void* user_data)

dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &number);

free(param);
}

static void separate_param_append(DBusMessageIter* iter, void* user_data)
Expand Down Expand Up @@ -1348,7 +1346,7 @@ int tapi_call_separate_call(tapi_context context,

int tapi_call_hangup_multiparty(tapi_context context, int slot_id)
{
return manage_call_proxy_method(context, slot_id, "multiparty_hangup");
return manage_call_proxy_method(context, slot_id, "HangupMultiparty");
}

int tapi_call_send_tones(void* context, int slot_id, char* tones)
Expand Down
145 changes: 35 additions & 110 deletions src/tapi_ss.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,97 +311,6 @@ static void enable_fdn_param_append(DBusMessageIter* iter, void* user_data)
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &passwd);
}

static void fill_ss_cb_cf_response_info(DBusMessageIter* iter,
tapi_ss_initiate_info* info)
{
while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;

dbus_message_iter_recurse(iter, &entry);
dbus_message_iter_get_basic(&entry, &info->append_service);

dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
dbus_message_iter_get_basic(&value, &info->append_service_value);

dbus_message_iter_next(iter);
}
}

static void fill_ss_initiate_cb_or_cf_service(DBusMessageIter* iter,
tapi_ss_initiate_info* info)
{
while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
DBusMessageIter entry, value, dict;

dbus_message_iter_recurse(iter, &entry);
dbus_message_iter_get_basic(&entry, &info->ss_service_operation);

dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
dbus_message_iter_get_basic(&value, &info->service_operation_requested);

dbus_message_iter_next(&value);
dbus_message_iter_recurse(&value, &dict);

fill_ss_cb_cf_response_info(&dict, info);

dbus_message_iter_next(iter);
}
}

static void fill_ss_initiate_cw_append_service(DBusMessageIter* iter,
tapi_ss_initiate_info* info)
{
while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;

dbus_message_iter_recurse(iter, &entry);
dbus_message_iter_get_basic(&entry, &info->append_service);

dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
dbus_message_iter_get_basic(&value, &info->append_service_value);

dbus_message_iter_next(iter);
}
}

static void fill_ss_initiate_cw_service(DBusMessageIter* iter,
tapi_ss_initiate_info* info)
{
while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
DBusMessageIter entry, value;

dbus_message_iter_recurse(iter, &entry);
dbus_message_iter_get_basic(&entry, &info->ss_service_operation);

dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);

fill_ss_initiate_cw_append_service(&value, info);

dbus_message_iter_next(iter);
}
}

static void fill_ss_initiate_cs_service(DBusMessageIter* iter,
tapi_ss_initiate_info* info)
{
while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
DBusMessageIter entry, value;

dbus_message_iter_recurse(iter, &entry);
dbus_message_iter_get_basic(&entry, &info->ss_service_operation);

dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
dbus_message_iter_get_basic(&value, &info->call_setting_status);

dbus_message_iter_next(iter);
}
}

static void method_call_complete(DBusMessage* message, void* user_data)
{
tapi_async_handler* handler = user_data;
Expand Down Expand Up @@ -534,7 +443,8 @@ static void ss_initiate_complete(DBusMessage* message, void* user_data)
tapi_async_handler* handler;
tapi_async_result* ar;
tapi_async_function cb;
DBusMessageIter iter, value, var;
const char* name;
DBusMessageIter iter, var;
DBusError err;

handler = user_data;
Expand Down Expand Up @@ -576,25 +486,35 @@ static void ss_initiate_complete(DBusMessage* message, void* user_data)
goto done;
}

dbus_message_iter_recurse(&iter, &value);
dbus_message_iter_get_basic(&value, &info->ss_service_type);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
tapi_log_error("message iter type is not string in %s", __func__);
ar->status = ERROR;
goto done;
}

dbus_message_iter_next(&value);
dbus_message_iter_recurse(&value, &var);
dbus_message_iter_get_basic(&iter, &name);
dbus_message_iter_next(&iter);

if (dbus_message_iter_get_arg_type(&var) == DBUS_TYPE_VARIANT) {
if (strcmp(info->ss_service_type, "CallBarring") == 0
|| strcmp(info->ss_service_type, "CallForwarding") == 0) {
fill_ss_initiate_cb_or_cf_service(&var, info);
} else if (strcmp(info->ss_service_type, "CallWaiting") == 0) {
fill_ss_initiate_cw_service(&var, info);
} else if (strcmp(info->ss_service_type, "USSD") == 0) {
dbus_message_iter_get_basic(&var, &info->ussd_response);
} else {
fill_ss_initiate_cs_service(&var, info);
}
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
tapi_log_error("message iter type is not variant in %s", __func__);
ar->status = ERROR;
goto done;
}

dbus_message_iter_recurse(&iter, &var);
if (strcmp(name, "USSD")) {
tapi_log_error("reponse is not ussd str in %s", __func__);
ar->status = ERROR;
goto done;
}

if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING) {
tapi_log_error("get ussd str failed in %s", __func__);
ar->status = ERROR;
goto done;
}

dbus_message_iter_get_basic(&var, &info->ussd_response);
ar->data = info;
ar->status = OK;

Expand All @@ -606,7 +526,7 @@ static void ss_initiate_complete(DBusMessage* message, void* user_data)

static void ss_send_ussd_cb(DBusMessage* message, void* user_data)
{
DBusMessageIter iter, value;
DBusMessageIter iter;
tapi_async_handler* handler;
tapi_async_result* ar;
tapi_async_function cb;
Expand Down Expand Up @@ -645,8 +565,13 @@ static void ss_send_ussd_cb(DBusMessage* message, void* user_data)
goto done;
}

dbus_message_iter_recurse(&iter, &value);
dbus_message_iter_get_basic(&value, &response);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
tapi_log_error("message iter type is not string in %s", __func__);
ar->status = ERROR;
goto done;
}

dbus_message_iter_get_basic(&iter, &response);

ar->data = response;
ar->status = OK;
Expand Down
56 changes: 41 additions & 15 deletions tools/telephony_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,21 +577,7 @@ static void ss_event_response(tapi_async_result* result)
break;
case EVENT_INITIATE_SERVICE_DONE:
info = (tapi_ss_initiate_info*)result->data;
if (strcmp(info->ss_service_type, "CallBarring") == 0
|| strcmp(info->ss_service_type, "CallForwarding") == 0) {
syslog(LOG_DEBUG, "service type : %s (%s, %s, %s, %s) \n", info->ss_service_type,
info->ss_service_operation, info->service_operation_requested,
info->append_service, info->append_service_value);
} else if (strcmp(info->ss_service_type, "CallWaiting") == 0) {
syslog(LOG_DEBUG, "service type : %s (%s, %s, %s) \n", info->ss_service_type,
info->ss_service_operation, info->append_service, info->append_service_value);
} else if (strcmp(info->ss_service_type, "USSD") == 0) {
syslog(LOG_DEBUG, "service type : %s (%s) \n",
info->ss_service_type, info->ussd_response);
} else {
syslog(LOG_DEBUG, "service type : %s (%s, %s) \n", info->ss_service_type,
info->ss_service_operation, info->call_setting_status);
}
syslog(LOG_DEBUG, "USSD response: %s", info->ussd_response);
break;
case EVENT_QUERY_FDN_DONE:
syslog(LOG_DEBUG, "fdn enabled or disabled : %d \n", param);
Expand Down Expand Up @@ -1030,6 +1016,22 @@ static int telephonytool_cmd_hangup_all(tapi_context context, char* pargs)
return tapi_call_hangup_all_calls(context, atoi(slot_id));
}

static int telephonytool_cmd_hangup_multiparty(tapi_context context, char* pargs)
{
char* slot_id;
char* temp;

if (strlen(pargs) == 0)
return -EINVAL;

slot_id = strtok_r(pargs, " ", &temp);
if (!is_valid_slot_id_str(slot_id))
return -EINVAL;

syslog(LOG_DEBUG, "%s, slotId : %s\n", __func__, slot_id);
return tapi_call_hangup_multiparty(context, atoi(slot_id));
}

static int telephonytool_cmd_hangup_by_id(tapi_context context, char* pargs)
{
char dst[2][MAX_INPUT_ARGS_LEN];
Expand Down Expand Up @@ -1395,6 +1397,24 @@ static int telephonytool_cmd_get_default_voicecall_slot(tapi_context context, ch
return 0;
}

static int telephonytool_cmd_deflect_call(tapi_context context, char* pargs)
{
char dst[3][MAX_INPUT_ARGS_LEN];
int cnt = split_input(dst, 3, pargs, " ");
char* slot_id;

if (cnt != 3)
return -EINVAL;

slot_id = dst[0];
if (!is_valid_slot_id_str(dst[0]))
return -EINVAL;

syslog(LOG_DEBUG, "%s, slotId: %s, call_id: %s, phone_number: %s", __func__, slot_id, (char*)dst[1], (char*)dst[2]);

return tapi_call_deflect_by_id(context, atoi(slot_id), (char*)dst[1], (char*)dst[2]);
}

static int telephonytool_cmd_query_modem_list(tapi_context context, char* pargs)
{
if (strlen(pargs) > 0)
Expand Down Expand Up @@ -4447,6 +4467,9 @@ static struct telephonytool_cmd_s g_telephonytool_cmds[] = {
{ "hangup-all", CALL_CMD,
telephonytool_cmd_hangup_all,
"hangup all call (enter example : hangup-all 0 [slot_id])" },
{ "hangup-all-multiparty", CALL_CMD,
telephonytool_cmd_hangup_multiparty,
"hang up all multiparty calls (enter example : hangup-multiparty 0 [slot_id])" },
{ "get-call", CALL_CMD,
telephonytool_cmd_get_call,
"get call list/call info (enter example : get-call 0 "
Expand Down Expand Up @@ -4487,6 +4510,9 @@ static struct telephonytool_cmd_s g_telephonytool_cmds[] = {
{ "get-voicecall-slot", CALL_CMD,
telephonytool_cmd_get_default_voicecall_slot,
"get default data slot (enter example : get-voicecall-slot)" },
{ "deflect", CALL_CMD,
telephonytool_cmd_deflect_call,
"call deflect (enter example : deflect 0 /ril_0/voicecall01 15512345678)" },

/* Data Command */
{ "listen-data", DATA_CMD,
Expand Down
Loading