qmi: lte: Remove magic number use
PATCH 1/6 qmi: lte: Remove magic number use
Several commands were invoked using magic numbers, even though they're defined inside wds.h. Remove magic numbers from enumerations by introducing appropriate enums to wds.h. Similarly, use defined constants for parameter and result ids.
--- drivers/qmimodem/lte.c | 29 +++++++++++++++-------------- drivers/qmimodem/wds.h | 14 +++++++++++++- 2 files changed, 28 insertions(+), 15 deletions(-)
drivers/qmimodem/lte.c +15 -14
@@ -73,24 +73,23 @@ static void qmimodem_lte_set_default_attach_info(const struct ofono_lte *lte,uint8_t type;uint8_t index; } __attribute__((packed)) p = { - .type =0 ,/* 3GPP */ + .type =QMI_WDS_PROFILE_TYPE_3GPP , + .index = ldd->default_profile, };DBG ("" ); - p.index = ldd->default_profile; - param =qmi_param_new ();/* Profile selector */ -qmi_param_append (param,0x01 ,sizeof (p), &p); +qmi_param_append (param,QMI_WDS_PARAM_PROFILE_TYPE ,sizeof (p), &p);/* WDS APN Name */ qmi_param_append (param,QMI_WDS_PARAM_APN ,strlen (info->apn), info->apn);/* Modify profile */ -if (qmi_service_send (ldd->wds,0x28 , param, +if (qmi_service_send (ldd->wds,QMI_WDS_MODIFY_PROFILE , param, modify_profile_cb, cbd, l_free) >0 )return ;
@@ -114,6 +113,7 @@ static void reset_profile_cb(struct qmi_result *result, void *user_data)static void get_default_profile_cb (struct qmi_result *result,void *user_data) { +static const uint8_t RESULT_DEFAULT_PROFILE_NUMBER =0x1 ;struct ofono_lte *lte = user_data;struct lte_data *ldd =ofono_lte_get_data (lte);uint16_t error;
@@ -123,7 +123,7 @@ static void get_default_profile_cb(struct qmi_result *result, void *user_data)uint8_t type;uint8_t index; } __attribute__((packed)) p = { - .type =0 ,/* 3GPP */ + .type =QMI_WDS_PROFILE_TYPE_3GPP , };DBG ("" );
@@ -134,7 +134,8 @@ static void get_default_profile_cb(struct qmi_result *result, void *user_data) }/* Profile index */ -if (!qmi_result_get_uint8 (result,0x01 , &index)) { +if (!qmi_result_get_uint8 (result,RESULT_DEFAULT_PROFILE_NUMBER , + &index)) {ofono_error ("Failed query default profile" ); goto error; }
@@ -148,10 +149,10 @@ static void get_default_profile_cb(struct qmi_result *result, void *user_data) param =qmi_param_new ();/* Profile selector */ -qmi_param_append (param,0x01 ,sizeof (p), &p); +qmi_param_append (param,QMI_WDS_PARAM_PROFILE_TYPE ,sizeof (p), &p);/* Reset profile */ -if (qmi_service_send (ldd->wds,0x4b , param, +if (qmi_service_send (ldd->wds,QMI_WDS_RESET_PROFILE , param, reset_profile_cb, lte,NULL ) >0 )return ;
@@ -171,8 +172,8 @@ static void create_wds_cb(struct qmi_service *service, void *user_data)uint8_t type;uint8_t family; } __attribute((packed)) p = { - .type =0 ,/* 3GPP */ - .family =0 ,/* embedded */ + .type =QMI_WDS_PROFILE_TYPE_3GPP , + .family =QMI_WDS_PROFILE_FAMILY_EMBEDDED , };DBG ("" );
@@ -189,11 +190,11 @@ static void create_wds_cb(struct qmi_service *service, void *user_data) param =qmi_param_new ();/* Profile type */ -qmi_param_append (param,0x1 ,sizeof (p), &p); +qmi_param_append (param,QMI_WDS_PARAM_PROFILE_TYPE ,sizeof (p), &p);/* Get default profile */ -if (qmi_service_send (ldd->wds,0x49 , param, - get_default_profile_cb, lte,NULL ) >0 ) +if (qmi_service_send (ldd->wds,QMI_WDS_GET_DEFAULT_PROFILE_NUMBER , + param, get_default_profile_cb, lte,NULL ) >0 )return ;qmi_param_free (param);
drivers/qmimodem/wds.h +13 -1
@@ -20,13 +20,13 @@*/ /* Start WDS network interface */ +#define QMI_WDS_PARAM_PROFILE_TYPE 0x01#define QMI_WDS_PARAM_APN 0x14/* string */ #define QMI_WDS_PARAM_IP_FAMILY 0x19/* uint8 */ #define QMI_WDS_PARAM_USERNAME 0x17/* string */ #define QMI_WDS_PARAM_PASSWORD 0x18/* string */ #define QMI_WDS_PARAM_AUTHENTICATION_PREFERENCE 0x16/* uint8 */ -enum qmi_wds_authentication {QMI_WDS_AUTHENTICATION_PAP =0x1 ,QMI_WDS_AUTHENTICATION_CHAP =0x2 ,
@@ -57,6 +57,17 @@ enum qmi_wds_client_type { QMI_WDS_CLIENT_TYPE_TETHERED = 0x01, }; +enum qmi_wds_profile_type { +QMI_WDS_PROFILE_TYPE_3GPP =0x00 , +QMI_WDS_PROFILE_TYPE_3GPP2 =0x01 , +QMI_WDS_PROFILE_TYPE_EPC =0x02 , +}; + +enum qmi_wds_profile_family { +QMI_WDS_PROFILE_FAMILY_EMBEDDED =0x00 , +QMI_WDS_PROFILE_FAMILY_TETHERED =0x01 , +}; +enum qmi_wds_command {QMI_WDS_RESET =0x00 ,QMI_WDS_EVENT_REPORT =0x01 ,
@@ -83,6 +94,7 @@ enum qmi_wds_command {QMI_WDS_GET_CURRENT_DATA_BEARER_TECHNOLOGY =0x44 ,QMI_WDS_GET_DEFAULT_PROFILE_NUMBER =0x49 ,QMI_WDS_SET_DEFAULT_PROFILE_NUMBER =0x4A , +QMI_WDS_RESET_PROFILE =0x4B ,QMI_WDS_SET_IP_FAMILY =0x4D ,QMI_WDS_SET_AUTOCONNECT_SETTINGS =0x51 , QMI_WDS_GET_PDN_THROTTLE_INFO = 0x6C,
Signature · 1 line
2.44.0
PATCH 2/6 qmi: wds: Move enum conversion into wds.c
Introduce a new wds.c file which will house various utilities, such as enumeration conversion, that could be shared between multiple QMI based atom drivers. Move ofono_gprs_auth_method conversion here.
--- Makefile.am | 1 + drivers/qmimodem/gprs-context.c | 17 +---------------- drivers/qmimodem/wds.c | 25 +++++++++++++++++++++++++ drivers/qmimodem/wds.h | 2 ++ 4 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 drivers/qmimodem/wds.c
Makefile.am +1 -0
@@ -362,6 +362,7 @@ qmi_sources = drivers/qmimodem/qmi.h drivers/qmimodem/qmi.c \ drivers/qmimodem/pds.h \ drivers/qmimodem/common.h \ drivers/qmimodem/wda.h \ + drivers/qmimodem/wds.c \ drivers/qmimodem/voice.h builtin_sources += $(qmi_sources) \
drivers/qmimodem/gprs-context.c +1 -16
@@ -239,21 +239,6 @@ static void qmi_gprs_read_settings(struct ofono_gprs_context* gc,l_free (cbd); } -static uint8_t auth_method_to_qmi_auth (enum ofono_gprs_auth_method method) -{ -/* QMI uses a bitmap */ -switch (method) { -case OFONO_GPRS_AUTH_METHOD_CHAP : -return QMI_WDS_AUTHENTICATION_CHAP ; -case OFONO_GPRS_AUTH_METHOD_PAP : -return QMI_WDS_AUTHENTICATION_PAP ; -case OFONO_GPRS_AUTH_METHOD_NONE : -return 0 ; - } - -return 0 ; -} -static void qmi_activate_primary (struct ofono_gprs_context *gc,const struct ofono_gprs_primary_context *ctx,ofono_gprs_context_cb_t cb,void *user_data)
@@ -288,7 +273,7 @@ static void qmi_activate_primary(struct ofono_gprs_context *gc,qmi_param_append_uint8 (param,QMI_WDS_PARAM_IP_FAMILY , ip_family); - auth =auth_method_to_qmi_auth (ctx->auth_method); + auth =qmi_wds_auth_from_ofono (ctx->auth_method);qmi_param_append_uint8 (param,QMI_WDS_PARAM_AUTHENTICATION_PREFERENCE , auth);
drivers/qmimodem/wds.c new file +25 -0
@@ -0,0 +1,25 @@ +/* +* oFono - Open Source Telephony +* Copyright (C) 2024 Cruise, LLC +* +* SPDX-License-Identifier: LGPL-2.1-or-later +*/ + +#include "src/common.h" + +#include "wds.h" + +int qmi_wds_auth_from_ofono (enum ofono_gprs_auth_method method) +{ +/* QMI uses a bitmap */ +switch (method) { +case OFONO_GPRS_AUTH_METHOD_CHAP : +return QMI_WDS_AUTHENTICATION_CHAP ; +case OFONO_GPRS_AUTH_METHOD_PAP : +return QMI_WDS_AUTHENTICATION_PAP ; +case OFONO_GPRS_AUTH_METHOD_NONE : +return 0 ; + } + +return -ENOENT ; +}
drivers/qmimodem/wds.h +2 -0
@@ -108,3 +108,5 @@ enum qmi_wds_command {QMI_WDS_CONFIGURE_PROFILE_EVENT_LIST =0xA7 , QMI_WDS_PROFILE_CHANGED = 0xA8, }; + +int qmi_wds_auth_from_ofono (enum ofono_gprs_auth_method method);
Signature · 1 line
2.44.0
PATCH 3/6 qmi: lte: Support additional attributes
In reply to Denis KenziorAdd support for setting APN Type (IPV4, IPV6 or Dual), Username and Password attributes of the profile used for the default bearer.
--- drivers/qmimodem/lte.c | 21 +++++++++++++++++---- drivers/qmimodem/wds.c | 14 ++++++++++++++ drivers/qmimodem/wds.h | 1 + 3 files changed, 32 insertions(+), 4 deletions(-)
drivers/qmimodem/lte.c +17 -4
@@ -66,6 +66,10 @@ static void qmimodem_lte_set_default_attach_info(const struct ofono_lte *lte,const struct ofono_lte_default_attach_info *info, ofono_lte_cb_t cb, void *data) { + static const uint8_t PARAM_PDP_TYPE = 0x11; +static const uint8_t PARAM_USERNAME =0x1B ; +static const uint8_t PARAM_PASSWORD =0x1C ; +static const uint8_t PARAM_AUTHENTICATION_PREFERENCE =0x1D ;struct lte_data *ldd =ofono_lte_get_data (lte);struct cb_data *cbd =cb_data_new (cb, data);struct qmi_param * param;
@@ -76,19 +80,28 @@ static void qmimodem_lte_set_default_attach_info(const struct ofono_lte *lte, .type = QMI_WDS_PROFILE_TYPE_3GPP, .index = ldd->default_profile, }; +uint8_t auth =qmi_wds_auth_from_ofono (info->auth_method);DBG ("" ); param =qmi_param_new (); -/* Profile selector */ qmi_param_append (param,QMI_WDS_PARAM_PROFILE_TYPE ,sizeof (p), &p); - -/* WDS APN Name */ +qmi_param_append_uint8 (param,PARAM_PDP_TYPE , +qmi_wds_pdp_type_from_ofono (info->proto));qmi_param_append (param,QMI_WDS_PARAM_APN ,strlen (info->apn), info->apn); -/* Modify profile */ +qmi_param_append_uint8 (param,PARAM_AUTHENTICATION_PREFERENCE , auth); + +if (auth && info->username[0 ]) +qmi_param_append (param,PARAM_USERNAME , +strlen (info->username), info->username); + +if (auth && info->password[0 ]) +qmi_param_append (param,PARAM_PASSWORD , +strlen (info->password), info->password); +if (qmi_service_send (ldd->wds,QMI_WDS_MODIFY_PROFILE , param, modify_profile_cb, cbd, l_free) >0 )return ;
drivers/qmimodem/wds.c +14 -0
@@ -23,3 +23,17 @@ int qmi_wds_auth_from_ofono(enum ofono_gprs_auth_method method)return -ENOENT ; } + +int qmi_wds_pdp_type_from_ofono (enum ofono_gprs_proto proto) +{ +switch (proto) { +case OFONO_GPRS_PROTO_IP : +return QMI_WDS_PDP_TYPE_IPV4 ; +case OFONO_GPRS_PROTO_IPV6 : +return QMI_WDS_PDP_TYPE_IPV6 ; +case OFONO_GPRS_PROTO_IPV4V6 : +return QMI_WDS_PDP_TYPE_IPV4V6 ; + } + +return -ENOENT ; +}
drivers/qmimodem/wds.h +1 -0
@@ -110,3 +110,4 @@ enum qmi_wds_command { };int qmi_wds_auth_from_ofono (enum ofono_gprs_auth_method method); +int qmi_wds_pdp_type_from_ofono (enum ofono_gprs_proto proto);
Signature · 1 line
2.44.0
PATCH 4/6 qmi: gprs: Query default profile number at init
In reply to Denis KenziorThe current logic queries the default profile id every time the driver believes the default bearer has been attached. However, oFono does not modify the default profile number during its runtime. Query the default profile id at initialization time instead.
While here, remove some magic numbers in favor of defined constants.
--- drivers/qmimodem/gprs.c | 136 ++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 75 deletions(-)
drivers/qmimodem/gprs.c +61 -75
@@ -38,7 +38,7 @@ struct gprs_data {struct qmi_device *dev;struct qmi_service *nas;struct qmi_service *wds; -unsigned int last_auto_context_id; +unsigned int default_profile;uint16_t serving_system_indication_id; };
@@ -116,46 +116,12 @@ static void get_lte_attach_param_cb(struct qmi_result *result, void *user_data)if (qmi_result_get_uint8 (result,0x11 , &iptype))ofono_info ("LTE attach IP type: %hhd" , iptype); -ofono_gprs_cid_activated (gprs, data->last_auto_context_id, apn); +ofono_gprs_cid_activated (gprs, data->default_profile, apn);l_free (apn);return ; noapn: - data->last_auto_context_id =0 ; -ofono_error ("LTE bearer established but APN not set" ); -} - -static void get_default_profile_cb (struct qmi_result *result,void *user_data) -{ -struct ofono_gprs * gprs = user_data; -struct gprs_data *data =ofono_gprs_get_data (gprs); -uint16_t error; -uint8_t index; - -DBG ("" ); - -if (qmi_result_set_error (result, &error)) { -ofono_error ("Get default profile error: %hd" , error); - goto error; - } - -/* Profile index */ -if (!qmi_result_get_uint8 (result,0x01 , &index)) { -ofono_error ("Failed query default profile" ); - goto error; - } - -DBG ("Default profile index: %hhd" , index); - - data->last_auto_context_id = index; - -if (qmi_service_send (data->wds,QMI_WDS_GET_LTE_ATTACH_PARAMETERS , -NULL , get_lte_attach_param_cb, gprs,NULL ) >0 ) -return ; - -error: - data->last_auto_context_id =0 ;ofono_error ("LTE bearer established but APN not set" ); }
@@ -167,41 +133,16 @@ error:static void get_lte_attach_params (struct ofono_gprs * gprs) {struct gprs_data *data =ofono_gprs_get_data (gprs); -struct { -uint8_t type; -uint8_t family; - } __attribute((packed)) p = { - .type =0 ,/* 3GPP */ - .family =0 ,/* embedded */ - }; -struct qmi_param *param;DBG ("" ); -if (data->last_auto_context_id !=0 ) -return ;/* Established or in progress */ - -/* Set query in progress */ - data->last_auto_context_id =-1 ; - -/* First we query the default profile in order to find out which -* context the modem has activated. -*/ - param =qmi_param_new (); - -/* Profile type */ -qmi_param_append (param,0x1 ,sizeof (p), &p); - -if (qmi_service_send (data->wds,QMI_WDS_GET_DEFAULT_PROFILE_NUMBER , - param, get_default_profile_cb, gprs,NULL ) >0 ) +if (qmi_service_send (data->wds,QMI_WDS_GET_LTE_ATTACH_PARAMETERS , +NULL , get_lte_attach_param_cb, gprs,NULL ) >0 )return ; - -qmi_param_free (param); }static int handle_ss_info (struct qmi_result *result,struct ofono_gprs *gprs) { -struct gprs_data *data =ofono_gprs_get_data (gprs);int status;int tech;int bearer_tech;
@@ -222,8 +163,6 @@ static int handle_ss_info(struct qmi_result *result, struct ofono_gprs *gprs)*/ get_lte_attach_params (gprs); } - }else { - data->last_auto_context_id =0 ; }/* DC is optional so only notify on successful extraction */
@@ -337,20 +276,29 @@ static void qmi_attached_status(struct ofono_gprs *gprs,l_free (cbd); } -static void create_wds_cb (struct qmi_service *service,void *user_data) +static void get_default_profile_cb (struct qmi_result *result,void *user_data) { +static const uint8_t RESULT_DEFAULT_PROFILE_NUMBER =0x1 ;struct ofono_gprs *gprs = user_data;struct gprs_data *data =ofono_gprs_get_data (gprs); +uint16_t error; +uint8_t index; -DBG ("" ); +if (qmi_result_set_error (result, &error)) { +ofono_error ("Get default profile error: %hd" , error); + goto error; + } -if (!service) { -ofono_error ("Failed to request WDS service" ); -ofono_gprs_remove (gprs); -return ; +/* Profile index */ +if (!qmi_result_get_uint8 (result,RESULT_DEFAULT_PROFILE_NUMBER , + &index)) { +ofono_error ("Failed query default profile" ); + goto error; } - data->wds = service; +DBG ("Default profile index: %hhd" , index); + data->default_profile = index; +ofono_gprs_set_cid_range (gprs, index, index);/* * First get the SS info - the modem may already be connected,
@@ -358,15 +306,53 @@ static void create_wds_cb(struct qmi_service *service, void *user_data)*/ qmi_service_send (data->nas,QMI_NAS_GET_SERVING_SYSTEM ,NULL , ss_info_notify, gprs,NULL ); - data->serving_system_indication_id =qmi_service_register (data->nas,QMI_NAS_SERVING_SYSTEM_INDICATION , ss_info_notify, gprs,NULL ); -ofono_gprs_set_cid_range (gprs,1 ,1 ); -ofono_gprs_register (gprs); +return ; +error: +ofono_gprs_remove (gprs); +} + +static void create_wds_cb (struct qmi_service *service,void *user_data) +{ +struct ofono_gprs *gprs = user_data; +struct gprs_data *data =ofono_gprs_get_data (gprs); +struct { +uint8_t type; +uint8_t family; + } __attribute((packed)) p = { + .type =QMI_WDS_PROFILE_TYPE_3GPP , + .family =QMI_WDS_PROFILE_FAMILY_EMBEDDED , + }; +struct qmi_param *param; + +DBG ("" ); + +if (!service) { +ofono_error ("Failed to request WDS service" ); + goto error; + } + + data->wds = service; + +/* +* Query the default profile. We never change the default profile +* number, so querying it once should be sufficient +*/ + param =qmi_param_new (); +qmi_param_append (param,QMI_WDS_PARAM_PROFILE_TYPE ,sizeof (p), &p); + +if (qmi_service_send (data->wds,QMI_WDS_GET_DEFAULT_PROFILE_NUMBER , + param, get_default_profile_cb, gprs,NULL ) >0 ) +return ; + +qmi_param_free (param); +error: +ofono_gprs_remove (gprs); }static void create_nas_cb (struct qmi_service *service,void *user_data)
Signature · 1 line
2.44.0
PATCH 5/6 udevng: Add "option" module managed ports to gobi driver
In reply to Denis KenziorThis makes sure that any tty ports that are managed / created by the "option" module can still be utilized by the gobi driver.
--- plugins/udevng.c | 1 + 1 file changed, 1 insertion(+)
plugins/udevng.c +1 -0
@@ -2014,6 +2014,7 @@ static struct { { "hso", "hso" }, { "gobi", "qmi_wwan" }, { "gobi", "qcserial" }, + { "gobi", "option" }, { "sierra", "qmi_wwan", "1199" }, { "sierra", "qcserial", "1199" }, { "sierra", "sierra" },
Signature · 1 line
2.44.0
PATCH 6/6 udevng: Support Quectel RM502Q
In reply to Denis Kenzior[37312.033140] usb 4-1: New USB device found, idVendor=2c7c, idProduct=0800, bcdDevice= 4.14 [37312.033149] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [37312.033151] usb 4-1: Product: RM502Q-AE [37312.033153] usb 4-1: Manufacturer: Quectel --- plugins/udevng.c | 3 +++ 1 file changed, 3 insertions(+)
plugins/udevng.c +3 -0
@@ -2053,6 +2053,9 @@ static struct { { "quectelqmi", "qcserial", "2c7c", "0195" }, { "quectelqmi", "qmi_wwan", "2c7c", "0296" }, { "quectelqmi", "qcserial", "2c7c", "0296" }, + { "quectelqmi", "qmi_wwan", "2c7c", "0800" }, + { "quectelqmi", "qcserial", "2c7c", "0800" }, + { "quectelqmi", "option", "2c7c", "0800" }, { "quectelqmi", "qmi_wwan_q", "2c7c", "0452" }, { "ublox", "cdc_acm", "1546", "1010" }, { "ublox", "cdc_ncm", "1546", "1010" },
Signature · 1 line
2.44.0
This series was applied to ofono.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to ofono.git (master)
by Denis Kenzior <[email protected]>:
Quoted 8 lines · On Mon, 29 Apr 2024 10:56:53 -0500 you wrote:
Several commands were invoked using magic numbers, even though they're defined inside
wds.h. Remove magic numbers from enumerations by introducing appropriate enums towds.h. Similarly, use defined constants for parameter and result ids.--- drivers/qmimodem/lte.c | 29 +++++++++++++++-------------- drivers/qmimodem/wds.h | 14 +++++++++++++- 2 files changed, 28 insertions(+), 15 deletions(-)
Here is the summary with links:
- [1/6] qmi: lte: Remove magic number use
https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=758a6ea7faed - [2/6] qmi: wds: Move enum conversion into wds.c https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=e1756a883d8a - [3/6] qmi: lte: Support additional attributes https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=901835d0f265 - [4/6] qmi: gprs: Query default profile number at init https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=63a6b34de475 - [5/6] udevng: Add "option" module managed ports to gobi driver https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=cb4f0876de81 - [6/6] udevng: Support Quectel RM502Q https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=8254e8ff1553
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html