Skip to content

Commit ee7cd10

Browse files
bbilasjukkar
authored andcommitted
drivers: modem: improve modem context RSSI member
The previous bf68b67 commit incorrectly passes minfo.mdm_rssi value to the modem context data_rssi member during the driver initialization which causes the `modem info` shell command to return 0 as RSSI value. Fix that by changing data_rssi modem ctx member to a pointer that is assigned to the RSSI variable stored within the modem driver context structure. Signed-off-by: Bartosz Bilas <[email protected]>
1 parent 69f1236 commit ee7cd10

File tree

9 files changed

+41
-33
lines changed

9 files changed

+41
-33
lines changed

drivers/modem/gsm_ppp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ static int gsm_init(const struct device *dev)
11151115
gsm->context.data_imsi = minfo.mdm_imsi;
11161116
gsm->context.data_iccid = minfo.mdm_iccid;
11171117
#endif /* CONFIG_MODEM_SIM_NUMBERS */
1118-
gsm->context.data_rssi = minfo.mdm_rssi;
1118+
gsm->context.data_rssi = &minfo.mdm_rssi;
11191119
#endif /* CONFIG_MODEM_SHELL */
11201120

11211121
gsm->context.is_automatic_oper = false;

drivers/modem/hl7800.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ struct hl7800_iface_ctx {
519519
char mdm_active_bands_string[MDM_HL7800_LTE_BAND_STR_SIZE];
520520
char mdm_bands_string[MDM_HL7800_LTE_BAND_STR_SIZE];
521521
char mdm_imsi[MDM_HL7800_IMSI_MAX_STR_SIZE];
522+
int mdm_rssi;
522523
uint16_t mdm_bands_top;
523524
uint32_t mdm_bands_middle;
524525
uint32_t mdm_bands_bottom;
@@ -860,7 +861,7 @@ static void event_handler(enum mdm_hl7800_event event, void *event_data)
860861

861862
void mdm_hl7800_get_signal_quality(int *rsrp, int *sinr)
862863
{
863-
*rsrp = ictx.mdm_ctx.data_rssi;
864+
*rsrp = ictx.mdm_rssi;
864865
*sinr = ictx.mdm_sinr;
865866
}
866867

@@ -1243,7 +1244,7 @@ void mdm_hl7800_generate_status_events(void)
12431244
#ifdef CONFIG_MODEM_HL7800_FW_UPDATE
12441245
generate_fota_state_event();
12451246
#endif
1246-
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_ctx.data_rssi);
1247+
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_rssi);
12471248
event_handler(HL7800_EVENT_SINR, &ictx.mdm_sinr);
12481249
event_handler(HL7800_EVENT_APN_UPDATE, &ictx.mdm_apn);
12491250
event_handler(HL7800_EVENT_RAT, &ictx.mdm_rat);
@@ -3385,7 +3386,7 @@ static bool on_cmd_atcmdinfo_rssi(struct net_buf **buf, uint16_t len)
33853386
search_start = delims[i] + 1;
33863387
}
33873388
/* the first value in the message is the RSRP */
3388-
ictx.mdm_ctx.data_rssi = strtol(value, NULL, 10);
3389+
ictx.mdm_rssi = strtol(value, NULL, 10);
33893390
/* the 4th ',' (last in the msg) is the start of the SINR */
33903391
ictx.mdm_sinr = strtol(delims[3] + 1, NULL, 10);
33913392
if ((delims[1] - delims[0]) == 1) {
@@ -3394,9 +3395,9 @@ static bool on_cmd_atcmdinfo_rssi(struct net_buf **buf, uint16_t len)
33943395
*/
33953396
LOG_INF("RSSI (RSRP): UNKNOWN");
33963397
} else {
3397-
LOG_INF("RSSI (RSRP): %d SINR: %d", ictx.mdm_ctx.data_rssi,
3398+
LOG_INF("RSSI (RSRP): %d SINR: %d", ictx.mdm_rssi,
33983399
ictx.mdm_sinr);
3399-
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_ctx.data_rssi);
3400+
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_rssi);
34003401
event_handler(HL7800_EVENT_SINR, &ictx.mdm_sinr);
34013402
}
34023403
done:
@@ -5854,6 +5855,7 @@ static int hl7800_init(const struct device *dev)
58545855
#ifdef CONFIG_MODEM_SIM_NUMBERS
58555856
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
58565857
#endif
5858+
ictx.mdm_ctx.data_rssi = &ictx.mdm_rssi;
58575859

58585860
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
58595861
mdm_recv_buf, sizeof(mdm_recv_buf));

drivers/modem/modem_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct modem_context {
7171
int data_lac;
7272
int data_cellid;
7373
#endif
74-
int data_rssi;
74+
int *data_rssi;
7575
bool is_automatic_oper;
7676
/* pin config */
7777
struct modem_pin *pins;

drivers/modem/modem_receiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct mdm_receiver_context {
3737
char *data_imsi;
3838
#endif
3939
char *data_iccid;
40-
int data_rssi;
40+
int *data_rssi;
4141
};
4242

4343
/**

drivers/modem/modem_shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int cmd_modem_list(const struct shell *shell, size_t argc,
8888
mdm_ctx->data_lac,
8989
mdm_ctx->data_cellid,
9090
#endif
91-
mdm_ctx->data_rssi);
91+
mdm_ctx->data_rssi ? *mdm_ctx->data_rssi : 0);
9292
}
9393
}
9494

@@ -223,7 +223,7 @@ static int cmd_modem_info(const struct shell *shell, size_t argc, char *argv[])
223223
mdm_ctx->data_model,
224224
mdm_ctx->data_revision,
225225
mdm_ctx->data_imei,
226-
mdm_ctx->data_rssi);
226+
mdm_ctx->data_rssi ? *mdm_ctx->data_rssi : 0);
227227

228228
shell_fprintf(shell, SHELL_NORMAL,
229229
"GSM 07.10 muxing : %s\n",

drivers/modem/quectel-bg9x.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_csq)
231231

232232
/* Check the RSSI value. */
233233
if (rssi == 31) {
234-
mctx.data_rssi = -51;
234+
mdata.mdm_rssi = -51;
235235
} else if (rssi >= 0 && rssi <= 31) {
236-
mctx.data_rssi = -114 + ((rssi * 2) + 1);
236+
mdata.mdm_rssi = -114 + ((rssi * 2) + 1);
237237
} else {
238-
mctx.data_rssi = -1000;
238+
mdata.mdm_rssi = -1000;
239239
}
240240

241-
LOG_INF("RSSI: %d", mctx.data_rssi);
241+
LOG_INF("RSSI: %d", mdata.mdm_rssi);
242242
return 0;
243243
}
244244

@@ -1035,13 +1035,13 @@ static int modem_setup(void)
10351035

10361036
/* Keep trying to read RSSI until we get a valid value - Eventually, exit. */
10371037
while (counter++ < MDM_WAIT_FOR_RSSI_COUNT &&
1038-
(mctx.data_rssi >= 0 || mctx.data_rssi <= -1000)) {
1038+
(mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000)) {
10391039
modem_rssi_query_work(NULL);
10401040
k_sleep(MDM_WAIT_FOR_RSSI_DELAY);
10411041
}
10421042

10431043
/* Is the RSSI invalid ? */
1044-
if (mctx.data_rssi >= 0 || mctx.data_rssi <= -1000) {
1044+
if (mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000) {
10451045
rssi_retry_count++;
10461046

10471047
if (rssi_retry_count >= MDM_NETWORK_RETRY_COUNT) {
@@ -1180,6 +1180,7 @@ static int modem_init(const struct device *dev)
11801180
mctx.data_imsi = mdata.mdm_imsi;
11811181
mctx.data_iccid = mdata.mdm_iccid;
11821182
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
1183+
mctx.data_rssi = &mdata.mdm_rssi;
11831184

11841185
/* pin setup */
11851186
mctx.pins = modem_pins;

drivers/modem/quectel-bg9x.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct modem_data {
100100
char mdm_imsi[MDM_IMSI_LENGTH];
101101
char mdm_iccid[MDM_ICCID_LENGTH];
102102
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
103+
int mdm_rssi;
103104

104105
/* bytes written to socket in last transaction */
105106
int sock_written;

drivers/modem/ublox-sara-r4.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ struct modem_data {
161161
char mdm_revision[MDM_REVISION_LENGTH];
162162
char mdm_imei[MDM_IMEI_LENGTH];
163163
char mdm_imsi[MDM_IMSI_LENGTH];
164+
int mdm_rssi;
164165

165166
#if defined(CONFIG_MODEM_UBLOX_SARA_AUTODETECT_VARIANT)
166167
/* modem variant */
@@ -658,13 +659,13 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_cesq)
658659
rsrp = ATOI(argv[5], 0, "rsrp");
659660
rxlev = ATOI(argv[0], 0, "rxlev");
660661
if (rsrp >= 0 && rsrp <= 97) {
661-
mctx.data_rssi = -140 + (rsrp - 1);
662-
LOG_INF("RSRP: %d", mctx.data_rssi);
662+
mdata.mdm_rssi = -140 + (rsrp - 1);
663+
LOG_INF("RSRP: %d", mdata.mdm_rssi);
663664
} else if (rxlev >= 0 && rxlev <= 63) {
664-
mctx.data_rssi = -110 + (rxlev - 1);
665-
LOG_INF("RSSI: %d", mctx.data_rssi);
665+
mdata.mdm_rssi = -110 + (rxlev - 1);
666+
LOG_INF("RSSI: %d", mdata.mdm_rssi);
666667
} else {
667-
mctx.data_rssi = -1000;
668+
mdata.mdm_rssi = -1000;
668669
LOG_INF("RSRP/RSSI not known");
669670
}
670671

@@ -681,15 +682,15 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_csq)
681682

682683
rssi = ATOI(argv[0], 0, "signal_power");
683684
if (rssi == 31) {
684-
mctx.data_rssi = -46;
685+
mdata.mdm_rssi = -46;
685686
} else if (rssi >= 0 && rssi <= 31) {
686687
/* FIXME: This value depends on the RAT */
687-
mctx.data_rssi = -110 + ((rssi * 2) + 1);
688+
mdata.mdm_rssi = -110 + ((rssi * 2) + 1);
688689
} else {
689-
mctx.data_rssi = -1000;
690+
mdata.mdm_rssi = -1000;
690691
}
691692

692-
LOG_INF("RSSI: %d", mctx.data_rssi);
693+
LOG_INF("RSSI: %d", mdata.mdm_rssi);
693694
return 0;
694695
}
695696
#endif
@@ -1320,13 +1321,13 @@ static void modem_reset(void)
13201321
counter = 0;
13211322
/* wait for RSSI < 0 and > -1000 */
13221323
while (counter++ < MDM_WAIT_FOR_RSSI_COUNT &&
1323-
(mctx.data_rssi >= 0 ||
1324-
mctx.data_rssi <= -1000)) {
1324+
(mdata.mdm_rssi >= 0 ||
1325+
mdata.mdm_rssi <= -1000)) {
13251326
modem_rssi_query_work(NULL);
13261327
k_sleep(MDM_WAIT_FOR_RSSI_DELAY);
13271328
}
13281329

1329-
if (mctx.data_rssi >= 0 || mctx.data_rssi <= -1000) {
1330+
if (mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000) {
13301331
retry_count++;
13311332
if (retry_count >= MDM_NETWORK_RETRY_COUNT) {
13321333
LOG_ERR("Failed network init. Too many attempts!");
@@ -2195,6 +2196,7 @@ static int modem_init(const struct device *dev)
21952196
mctx.data_model = mdata.mdm_model;
21962197
mctx.data_revision = mdata.mdm_revision;
21972198
mctx.data_imei = mdata.mdm_imei;
2199+
mctx.data_rssi = &mdata.mdm_rssi;
21982200

21992201
/* pin setup */
22002202
mctx.pins = modem_pins;

drivers/modem/wncm14a2a.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct wncm14a2a_iface_ctx {
204204
char mdm_model[MDM_MODEL_LENGTH];
205205
char mdm_revision[MDM_REVISION_LENGTH];
206206
char mdm_imei[MDM_IMEI_LENGTH];
207+
int mdm_rssi;
207208

208209
/* modem state */
209210
int ev_csps;
@@ -663,8 +664,8 @@ static void on_cmd_atcmdinfo_rssi(struct net_buf **buf, uint16_t len)
663664
}
664665

665666
if (i > 0) {
666-
ictx.mdm_ctx.data_rssi = atoi(value);
667-
LOG_INF("RSSI: %d", ictx.mdm_ctx.data_rssi);
667+
ictx.mdm_rssi = atoi(value);
668+
LOG_INF("RSSI: %d", ictx.mdm_rssi);
668669
} else {
669670
LOG_WRN("Bad format found for RSSI");
670671
}
@@ -1398,15 +1399,15 @@ static void wncm14a2a_modem_reset(void)
13981399
counter = 0;
13991400
/* wait for RSSI > -1000 and != 0 */
14001401
while (counter++ < 15 &&
1401-
(ictx.mdm_ctx.data_rssi <= -1000 ||
1402-
ictx.mdm_ctx.data_rssi == 0)) {
1402+
(ictx.mdm_rssi <= -1000 ||
1403+
ictx.mdm_rssi == 0)) {
14031404
/* stop RSSI delay work */
14041405
k_work_cancel_delayable(&ictx.rssi_query_work);
14051406
wncm14a2a_rssi_query_work(NULL);
14061407
k_sleep(K_SECONDS(2));
14071408
}
14081409

1409-
if (ictx.mdm_ctx.data_rssi <= -1000 || ictx.mdm_ctx.data_rssi == 0) {
1410+
if (ictx.mdm_rssi <= -1000 || ictx.mdm_rssi == 0) {
14101411
retry_count++;
14111412
if (retry_count > 3) {
14121413
LOG_ERR("Failed network init. Too many attempts!");
@@ -1486,6 +1487,7 @@ static int wncm14a2a_init(const struct device *dev)
14861487
#ifdef CONFIG_MODEM_SIM_NUMBERS
14871488
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
14881489
#endif
1490+
ictx.mdm_ctx.data_rssi = &ictx.mdm_rssi;
14891491

14901492
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
14911493
mdm_recv_buf, sizeof(mdm_recv_buf));

0 commit comments

Comments
 (0)