ublox: network-registration: Handle UREG unsolicited during poll
PATCH 1/1 ublox: network-registration: Handle UREG unsolicited during poll
From: Richard Röjfors <[email protected]>
In the case a unsolicited indication for UREG was received while the status was polled. The poll response failed to parse. This since the unsolicited indication only carries one parameter, while the poll response is expected to carry two.
Update the code to loop until the response is found.
The log below shows a case where this happened.
10:07:55 ofonod[520]: Aux: > AT+UREG?\r
10:07:55 ofonod[520]: Aux: < \r\n+CGREG: 4\r\n\r\n+UREG: 0\r\n\r\n+CIEV: 9,1\r\n 10:07:55 ofonod[520]: src/gprs.c:ofono_gprs_status_notify() /ublox_0 status unknown (4) 10:07:55 ofonod[520]: src/gprs.c:ofono_gprs_detached_notify() /ublox_0 10:07:55 ofonod[520]: Aux: < \r\n+UREG: 1,0\r\n
10:07:55 ofonod[520]: Aux: < \r\nOK\r\n
--- drivers/ubloxmodem/network-registration.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/ubloxmodem/network-registration.c +12 -6
@@ -288,15 +288,21 @@ static void ublox_ureg_cb(gboolean ok, GAtResult *result,g_at_result_iter_init (&iter, result); -if (!g_at_result_iter_next (&iter,"+UREG:" )) -return ; +while (g_at_result_iter_next (&iter,"+UREG:" )) { +if (!g_at_result_iter_next_number (&iter, &enabled)) +return ; -if (!g_at_result_iter_next_number (&iter, &enabled)) -return ; +/* Sometimes we get an unsolicited UREG here, skip it */ +if (!g_at_result_iter_next_number (&iter, &state)) +continue ; -if (!g_at_result_iter_next_number (&iter, &state)) -return ; + goto parsed_state; + } + +/* In case we get here, the response was not parsed */ + goto error; +parsed_state: tech =ublox_ureg_state_to_tech (state);if (tech <0 )/* No valid UREG status, we have to trust CREG... */
Signature · 1 line
2.20.1
Hi Richard,
Quoted 34 lines · richard.rojfors(a)gmail.com
From: Richard Röjfors <[email protected]>
In the case a unsolicited indication for UREG was received while the status was polled. The poll response failed to parse. This since the unsolicited indication only carries one parameter, while the poll response is expected to carry two.
Update the code to loop until the response is found.
The log below shows a case where this happened.
10:07:55 ofonod[520]: Aux: > AT+UREG?\r
10:07:55 ofonod[520]: Aux: < \r\n+CGREG: 4\r\n\r\n+UREG: 0\r\n\r\n+CIEV: 9,1\r\n 10:07:55 ofonod[520]: src/gprs.c:ofono_gprs_status_notify() /ublox_0 status unknown (4) 10:07:55 ofonod[520]: src/gprs.c:ofono_gprs_detached_notify() /ublox_0 10:07:55 ofonod[520]: Aux: < \r\n+UREG: 1,0\r\n
10:07:55 ofonod[520]: Aux: < \r\nOK\r\n--- drivers/ubloxmodem/network-registration.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)drivers/ubloxmodem/network-registration.c +3
-2@@ -288,15 +288,21 @@ static void ublox_ureg_cb(gboolean ok, GAtResult *result,g_at_result_iter_init (&iter, result); -if (!g_at_result_iter_next (&iter,"+UREG:" )) -return ; +while (g_at_result_iter_next (&iter,"+UREG:" )) { +if (!g_at_result_iter_next_number (&iter, &enabled)) +return ;
drivers/ubloxmodem/network-registration.c static void ublox_ureg_cb(gboolean ok, GAtResult *result, · line 299
Quoted 10 lines
drivers/ubloxmodem/network-registration.c +4
-4-if (!g_at_result_iter_next_number (&iter, &enabled)) -return ; +/* Sometimes we get an unsolicited UREG here, skip it */ +if (!g_at_result_iter_next_number (&iter, &state)) +continue ; -if (!g_at_result_iter_next_number (&iter, &state)) -return ; + goto parsed_state;
Wouldn't it look nicer to just perform the ublox_ureg_state_to_tech steps here (i.e within the loop) without the goto?
drivers/ubloxmodem/network-registration.c static void ublox_ureg_cb(gboolean ok, GAtResult *result, · line 303
Quoted 4 lines
drivers/ubloxmodem/network-registration.c +4
-0+ } + +/* In case we get here, the response was not parsed */ + goto error;
Then this also becomes unnecessary.
drivers/ubloxmodem/network-registration.c static void ublox_ureg_cb(gboolean ok, GAtResult *result,
Quoted 6 lines
drivers/ubloxmodem/network-registration.c +1
-0+parsed_state: tech =ublox_ureg_state_to_tech (state);if (tech <0 )/* No valid UREG status, we have to trust CREG... */
Regards,
-Denis
Hi Denis,
Den tors 13 feb. 2020 kl 17:44 skrev Denis Kenzior <[email protected]>:
Quoted 8 lines
drivers/ubloxmodem/network-registration.c static void ublox_ureg_cb(gboolean ok, GAtResult *result, · line 299
Quoted 4 lines
drivers/ubloxmodem/network-registration.c +1
-2-if (!g_at_result_iter_next_number (&iter, &state)) -return ; + goto parsed_state;Wouldn't it look nicer to just perform the
ublox_ureg_state_to_techsteps here (i.e within the loop) without the goto?
Yes, its a good suggestion! I have sent a v2.
--Richard