diff mbox series

[1/6] qmi: lte: Remove magic number use

Message ID 20240429155726.51479-1-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 758a6ea7faedb2c12965a0d2cec8411cf4c93e34
Headers show
Series [1/6] qmi: lte: Remove magic number use | expand

Commit Message

Denis Kenzior April 29, 2024, 3:56 p.m. UTC
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(-)

Comments

patchwork-bot+ofono@kernel.org April 29, 2024, 7:10 p.m. UTC | #1
Hello:

This series was applied to ofono.git (master)
by Denis Kenzior <denkenz@gmail.com>:

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 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(-)

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!
diff mbox series

Patch

diff --git a/drivers/qmimodem/lte.c b/drivers/qmimodem/lte.c
index 6c08c312b3cb..7633572b39ef 100644
--- a/drivers/qmimodem/lte.c
+++ b/drivers/qmimodem/lte.c
@@ -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);
diff --git a/drivers/qmimodem/wds.h b/drivers/qmimodem/wds.h
index 3c9b534c1f82..6d7071fe244f 100644
--- a/drivers/qmimodem/wds.h
+++ b/drivers/qmimodem/wds.h
@@ -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,