ifx: adding Infineon modem self test
PATCH 1/1 ifx: adding Infineon modem self test
Hi,
Adding Infineon modem selftest to the plugin. It executes couple of AT commands, and based on the responses, it continues with ifx modem enabling or powers the modem down.
Thanks,
-- r.
--- plugins/ifx.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 92 insertions(+), 6 deletions(-)
plugins/ifx.c +92 -6
@@ -80,6 +80,12 @@ static const char *dlc_nodes[NUM_DLC] = { "/dev/ttyGSM1", "/dev/ttyGSM2",static const char *none_prefix[] = {NULL };static const char *xdrv_prefix[] = {"+XDRV:" ,NULL }; +static const char *empty_prefix[] = {"" ,NULL }; + +static const char *modem_self_tests[][2 ] = { + {"RTC Test" ,"at(a)rtc:rtc_gti_test_verify_32khz()" }, + {"Version Info Test" ,"at(a)vers:device_version_id()" }, + {NULL ,NULL } };struct ifx_data {GIOChannel *device;
@@ -99,6 +105,8 @@ struct ifx_data {int audio_loopback;struct ofono_sim *sim;gboolean have_sim; +guint self_test_timeout; +int self_test_idx; };static void ifx_debug (const char *str,void *user_data)
@@ -545,6 +553,82 @@ static gboolean mux_timeout_cb(gpointer user_data)return FALSE; } +static gboolean self_test_timeout_cb (gpointer user_data) +{ +struct ofono_modem *modem = user_data; +struct ifx_data *data =ofono_modem_get_data (modem); + +ofono_error ("Timeout with modem self_test" ); +g_source_remove (data->self_test_timeout); + data->self_test_timeout =0 ; + +shutdown_device (data); +ofono_modem_set_powered (modem, FALSE); +return FALSE; +} + +static void ifx_self_test_get_device_resp (GAtResult *result,int test_id) +{ +GAtResultIter iter; +const char *str; + +ofono_info ("Modem Response: %s" , + modem_self_tests[test_id][0 ]); + +g_at_result_iter_init (&iter, result); + +while (g_at_result_iter_next (&iter,NULL )) { + +if (g_at_result_iter_next_string (&iter, &str)) +ofono_info ("Modem Response: %s" , str); + } +} + +static void ifx_self_test_cb (gboolean ok,GAtResult *result, +gpointer user_data) +{ +struct ofono_modem *modem = user_data; +struct ifx_data *data =ofono_modem_get_data (modem); + +if (ok) { + +if (data->self_test_timeout >0 ) { +g_source_remove (data->self_test_timeout); + data->self_test_timeout =0 ; + } + +ifx_self_test_get_device_resp (result, data->self_test_idx); + data->self_test_idx++; + +if (modem_self_tests[data->self_test_idx][1 ] !=NULL ) { + +g_at_chat_send (data->dlcs[AUX_DLC ], + modem_self_tests[data->self_test_idx][1 ], + empty_prefix, ifx_self_test_cb, modem,NULL ); + + data->self_test_timeout =g_timeout_add_seconds (10 , + self_test_timeout_cb, modem); +return ; + + }else { + +/* Enable MUX Channels */ + data->frame_size =1509 ; +g_at_chat_send (data->dlcs[AUX_DLC ], +"AT+CMUX=0,0,,1509,10,3,30,," ,NULL , + mux_setup_cb, modem,NULL ); + + data->mux_init_timeout =g_timeout_add_seconds (5 , + mux_timeout_cb, modem); +return ; + } + } + +ofono_error ("Modem %s: FAIL" , modem_self_tests[data->self_test_idx][0 ]); +shutdown_device (data); +ofono_modem_set_powered (modem, FALSE); +} +static int ifx_enable (struct ofono_modem *modem) {struct ifx_data *data =ofono_modem_get_data (modem);
@@ -598,15 +682,17 @@ static int ifx_enable(struct ofono_modem *modem)g_at_chat_send (chat,"ATE0 +CMEE=1" ,NULL ,NULL ,NULL ,NULL ); - data->frame_size =1509 ; +/* Execute Modem Self tests */ -g_at_chat_send (chat,"AT+CMUX=0,0,,1509,10,3,30,," ,NULL , - mux_setup_cb, modem,NULL ); + data->dlcs[AUX_DLC ] = chat; + data->self_test_idx =0 ; - data->mux_init_timeout =g_timeout_add_seconds (5 , mux_timeout_cb, - modem); +g_at_chat_send (data->dlcs[AUX_DLC ], + modem_self_tests[data->self_test_idx][1 ], + empty_prefix, ifx_self_test_cb, modem,NULL ); - data->dlcs[AUX_DLC ] = chat; + data->self_test_timeout =g_timeout_add_seconds (10 , + self_test_timeout_cb, modem);return -EINPROGRESS ; }
Signature · 1 line
1.7.0.4
Hi Robertino,
Quoted 3 lines
Adding Infineon modem selftest to the plugin. It executes couple of AT commands, and based on the responses, it continues with ifx modem enabling or powers the modem down.
didn't we conclude that the modem should do all these by itself? My understanding is that the modem executes these. And not that we have to trigger them.
Regards
Marcel
Bastian
Quoted 7 lines
Quoted 3 lines
Adding Infineon modem selftest to the plugin. It executes couple of AT commands, and based on the responses, it continues with ifx modem enabling or powers the modem down.
didn't we conclude that the modem should do all these by itself? My understanding is that the modem executes these. And not that we have to trigger them.
The conclusion was that these two test commands should be issued from the AP to ensure that the modem is functioning properly.
Cheers,
Waldo
Hi Waldo,
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Adding Infineon modem selftest to the plugin. It executes couple of AT commands, and based on the responses, it continues with ifx modem enabling or powers the modem down.
didn't we conclude that the modem should do all these by itself? My understanding is that the modem executes these. And not that we have to trigger them.
The conclusion was that these two test commands should be issued from the AP to ensure that the modem is functioning properly.
I am not aware of the conclusion. My understanding is still that the modem firmware is suppose to do its selftests all by itself.
So what is the reasoning behind doing these selftests from the host. Right now I am failing to see the benefit of these.
Regards
Marcel
Bastian
Quoted 4 lines
Quoted 1 line
The conclusion was that these two test commands should be issued from the AP to ensure that the modem is functioning properly.
I am not aware of the conclusion. My understanding is still that the modem firmware is suppose to do its selftests all by itself.
It does not.
Quoted 1 line
So what is the reasoning behind doing these selftests from the host.
It makes it easier for the host to record diagnostics / error codes this way. At the moment this is limited to recording it in the log file, as oFono doesn't provide a good way for reporting back error conditions when powering up a modem fails.
Cheers,
Waldo
Hi Waldo,
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
The conclusion was that these two test commands should be issued from the AP to ensure that the modem is functioning properly.
I am not aware of the conclusion. My understanding is still that the modem firmware is suppose to do its selftests all by itself.
It does not.
this is really new to me. Last time this has been talked about, that was different.
Quoted 3 lines
Quoted 1 line
So what is the reasoning behind doing these selftests from the host.
It makes it easier for the host to record diagnostics / error codes this way. At the moment this is limited to recording it in the log file, as oFono doesn't provide a good way for reporting back error conditions when powering up a modem fails.
There is nothing more that you can provide to the host anyway. Just having one AT command to read the selftest log from the modem would have been just fine. Right now I am not seeing any advantage why the host should execute selftests.
And essentially this really only makes sense once the oFono core can mark a modem as broken and then just not even try to re-enable it.
We don't even have a state for this since it was never a requirement to have such a state. While Lockdown comes pretty close, it is semantically something totally different.
There is also the other thing, that we have no numbers on the expected execution time of these selftests. This needs to be documented inside the code. Otherwise this gets out of control.
And just to make this clear. These are run on every oFono modem enabling execution. This is different from just on initial modem power on. Are you okay with the impact on modem enabling time?
Regards
Marcel
Hi Robertino,
Quoted 3 lines
static const char *none_prefix[] = { NULL }; static const char *xdrv_prefix[] = { "+XDRV:", NULL };
+static const char *empty_prefix[] = { "", NULL };
this is essentially to just passing NULL as argument. What are you trying to achieve here?
plugins/ifx.c static const char *dlc_nodes[NUM_DLC] = { "/dev/ttyGSM1", "/dev/ttyGSM2", · line 88
Quoted 4 lines
plugins/ifx.c +4
-0+static const char *modem_self_tests[][2 ] = { + {"RTC Test" ,"at(a)rtc:rtc_gti_test_verify_32khz()" }, + {"Version Info Test" ,"at(a)vers:device_version_id()" }, + {NULL ,NULL } };
The coding style is broken here. Please check the oFono source code for example on how to format these type of array correctly.
In addition the string array is wrong. It should be a struct array. The magic of [1] and [2] for picking the command or the text string is not intuitive and leads to unreadable code.
Quoted 12 lines
struct
ifx_data{plugins/ifx.c +2
-0GIOChannel *device;@@ -99,6 +105,8 @@ struct ifx_data {int audio_loopback;struct ofono_sim *sim;gboolean have_sim; +guint self_test_timeout; +int self_test_idx; };static void ifx_debug (const char *str,void *user_data)
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 561
Quoted 9 lines
plugins/ifx.c +6
-0@@ -545,6 +553,82 @@ static gboolean mux_timeout_cb(gpointer user_data)return FALSE; } +static gboolean self_test_timeout_cb (gpointer user_data) +{ +struct ofono_modem *modem = user_data; +struct ifx_data *data =ofono_modem_get_data (modem); + +ofono_error ("Timeout with modem self_test" );
You need an extra empty line here. The error is logically separated.
Review static gboolean mux_timeout_cb(gpointer user_data) · line 562
Quoted 1 line
(quoted diff) +1
-0+ g_source_remove(data->self_test_timeout);
You can not remove a source in its own callback. Have you tested this code path actually?
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 565
Quoted 3 lines
plugins/ifx.c +3
-0+ data->self_test_timeout =0 ; + +shutdown_device (data);
You can not use shutdown_device here since the multiplexer is not ready yet. If you decide the execute the selftests before bringing up the multiplexer then this is a different error path.
You need to cleanup data->dlcs[AUX_DLC] and data->device in this failure case.
Review static gboolean mux_timeout_cb(gpointer user_data) · line 566
Quoted 1 line
(quoted diff) +1
-0+ ofono_modem_set_powered(modem, FALSE);
This needs an extra empty before the return statement.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 571
Quoted 5 lines
plugins/ifx.c +5
-0+return FALSE; +} + +static void ifx_self_test_get_device_resp (GAtResult *result,int test_id) +{
The function is just wrong in conjunction with your array approach.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 576
Quoted 5 lines
plugins/ifx.c +5
-0+GAtResultIter iter; +const char *str; + +ofono_info ("Modem Response: %s" , + modem_self_tests[test_id][0 ]);
Can you give an example on a positive and negative selftest response here. I don't wanna spam the logs with details if everything is fine.
This should use ofono_error and that only in case of an error.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 584
Quoted 7 lines
plugins/ifx.c +7
-0+g_at_result_iter_init (&iter, result); + +while (g_at_result_iter_next (&iter,NULL )) { + +if (g_at_result_iter_next_string (&iter, &str)) +ofono_info ("Modem Response: %s" , str); + }
What is this while loop actually doing? How does a response look like.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 593
Quoted 9 lines
plugins/ifx.c +9
-0+} + +static void ifx_self_test_cb (gboolean ok,GAtResult *result, +gpointer user_data) +{ +struct ofono_modem *modem = user_data; +struct ifx_data *data =ofono_modem_get_data (modem); + +if (ok) {
This needs to be a if (!ok) here actually and then leaving this function with a simple error case.
Having the positive handling nested is not a good idea and we don't really do it that way.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 604
Quoted 11 lines
plugins/ifx.c +11
-0+ +if (data->self_test_timeout >0 ) { +g_source_remove (data->self_test_timeout); + data->self_test_timeout =0 ; + } + +ifx_self_test_get_device_resp (result, data->self_test_idx); + data->self_test_idx++; + +if (modem_self_tests[data->self_test_idx][1 ] !=NULL ) { +
No empty line here.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 611
Quoted 7 lines
plugins/ifx.c +7
-0+g_at_chat_send (data->dlcs[AUX_DLC ], + modem_self_tests[data->self_test_idx][1 ], + empty_prefix, ifx_self_test_cb, modem,NULL ); + + data->self_test_timeout =g_timeout_add_seconds (10 , + self_test_timeout_cb, modem); +return ;
No empty line here, but this is not needed in case of (!ok) anyway.
Review static gboolean mux_timeout_cb(gpointer user_data) · line 612
Quoted 2 lines
(quoted diff) +2
-0+ } else { +
No empty line here either.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 625
Quoted 11 lines
plugins/ifx.c +11
-0+/* Enable MUX Channels */ + data->frame_size =1509 ; +g_at_chat_send (data->dlcs[AUX_DLC ], +"AT+CMUX=0,0,,1509,10,3,30,," ,NULL , + mux_setup_cb, modem,NULL ); + + data->mux_init_timeout =g_timeout_add_seconds (5 , + mux_timeout_cb, modem); +return ; + } + }
With proper if (error) { ... ; return; } coding style this function becomes a lot more readable.
plugins/ifx.c static gboolean mux_timeout_cb(gpointer user_data) · line 628
Quoted 3 lines
plugins/ifx.c +3
-0+ +ofono_error ("Modem %s: FAIL" , modem_self_tests[data->self_test_idx][0 ]); +shutdown_device (data);
Again here, the shutdown_device call can not be used since the multiplexer is not yet brought up.
plugins/ifx.c static int ifx_enable(struct ofono_modem *modem) · line 683
Quoted 9 lines
plugins/ifx.c +3
-0+ofono_modem_set_powered (modem, FALSE); +} +static int ifx_enable (struct ofono_modem *modem) {struct ifx_data *data =ofono_modem_get_data (modem);@@ -598,15 +682,17 @@ static int ifx_enable(struct ofono_modem *modem)g_at_chat_send (chat,"ATE0 +CMEE=1" ,NULL ,NULL ,NULL ,NULL );
Now here is the question if we wanna execute ATE0 first or run the selftests first?
Quoted 7 lines
plugins/ifx.c +3
-3- data->frame_size =1509 ; +/* Execute Modem Self tests */ -g_at_chat_send (chat,"AT+CMUX=0,0,,1509,10,3,30,," ,NULL , - mux_setup_cb, modem,NULL ); + data->dlcs[AUX_DLC ] = chat; + data->self_test_idx =0 ;
plugins/ifx.c static int ifx_enable(struct ofono_modem *modem) · line 695
Quoted 10 lines
plugins/ifx.c +5
-3- data->mux_init_timeout =g_timeout_add_seconds (5 , mux_timeout_cb, - modem); +g_at_chat_send (data->dlcs[AUX_DLC ], + modem_self_tests[data->self_test_idx][1 ], + empty_prefix, ifx_self_test_cb, modem,NULL ); - data->dlcs[AUX_DLC ] = chat; + data->self_test_timeout =g_timeout_add_seconds (10 , + self_test_timeout_cb, modem);
Where does these 10 seconds come from?
Regards
Marcel