Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qmi: read sim status problem #9501

Closed
obsy opened this issue Mar 19, 2022 · 9 comments
Closed

qmi: read sim status problem #9501

obsy opened this issue Mar 19, 2022 · 9 comments

Comments

@obsy
Copy link
Contributor

obsy commented Mar 19, 2022

81832b3

Reading pin status in this way is wrong, this code return empty values. See debug script:

root@OpenWrt:~# uqmi -s -d /dev/cdc-wdm0 --get-pin-statu
{"pin1_status":"disabled","pin1_verify_tries":3,"pin1_unblock_tries":10,"pin2_status":"not_verified","pin2_verify_tries":3,"pin2_unblock_tries":10}
root@OpenWrt:~# uqmi -s -d /dev/cdc-wdm0  --uim-get-sim-state
{"pin1_status":"disabled","pin1_verify_tries":3,"pin1_unlock_tries":10,"pin2_status":"not_verified","pin2_verify_tries":3,"pin2_unlock_tries":10}
root@OpenWrt:~# cat ./a.sh 
#!/bin/sh
device=/dev/cdc-wdm0

. /usr/share/libubox/jshn.sh

json_load "$(uqmi -s -d "$device" --get-pin-status)" 2>&1 | grep -q Failed &&
	json_load "$(uqmi -s -d "$device" --uim-get-sim-state)"
json_get_var pin1_status pin1_status
json_get_var pin1_verify_tries pin1_verify_tries

echo "pin1_status: $pin1_status"
echo "pin1_verify_tries: $pin1_verify_tries"
root@OpenWrt:~#  ./a.sh 
pin1_status: 
pin1_verify_tries: 
root@OpenWrt:~# sh -x  ./a.sh 
+ device=/dev/cdc-wdm0
+ . /usr/share/libubox/jshn.sh
+ grep -q Failed
+ uqmi -s -d /dev/cdc-wdm0 --get-pin-status
+ json_load '{"pin1_status":"disabled","pin1_verify_tries":3,"pin1_unblock_tries":10,"pin2_status":"not_verified","pin2_verify_tries":3,"pin2_unblock_tries":10}'
+ json_get_var pin1_status pin1_status
+ local '__dest=pin1_status'
+ local __cur
+ _json_get_var __cur JSON_CUR
+ eval '__cur="$JSON_CUR"'
+ __cur=
+ local '__var=_pin1_status'
+ eval 'export -- "pin1_status=${_pin1_status:-}"; [ -n "${_pin1_status+x}${3+x}" ]'
+ export -- 'pin1_status='
+ '[' -n  ]
+ json_get_var pin1_verify_tries pin1_verify_tries
+ local '__dest=pin1_verify_tries'
+ local __cur
+ _json_get_var __cur JSON_CUR
+ eval '__cur="$JSON_CUR"'
+ __cur=
+ local '__var=_pin1_verify_tries'
+ eval 'export -- "pin1_verify_tries=${_pin1_verify_tries:-}"; [ -n "${_pin1_verify_tries+x}${3+x}" ]'
+ export -- 'pin1_verify_tries='
+ '[' -n  ]
+ echo 'pin1_status: '
pin1_status: 
+ echo 'pin1_verify_tries: '
pin1_verify_tries: 
root@OpenWrt:~# 

Tested with Quectel EC20

CC: @dangowrt

@dangowrt
Copy link
Member

@obsy I still had this on my to-do list. What was your reason for closing the issue now?

@obsy
Copy link
Contributor Author

obsy commented Mar 23, 2022

Because I don't know what the issue is. This code working for Askey modem, working for BroadMobi BM806U and not working for my Quectel EC20. I don't know if there is anything wrong with him. If you can, check it with some qmi modem.

@dangowrt
Copy link
Member

Does the output of --get-pin-status and --uim-get-sim-state @obsy has provided earlier belong to that Quectel EC20 modem?

@obsy
Copy link
Contributor Author

obsy commented Mar 23, 2022

Yes, from this EC20.

@obsy
Copy link
Contributor Author

obsy commented Mar 24, 2022

See:

#  ./a.sh 
{"pin1_status":"disabled","pin1_verify_tries":3,"pin1_unblock_tries":10,"pin2_status":"not_verified","pin2_verify_tries":3,"pin2_unblock_tries":10}
{ }
{ "pin1_status": "disabled", "pin1_verify_tries": 3, "pin1_unblock_tries": 10, "pin2_status": "not_verified", "pin2_verify_tries": 3, "pin2_unblock_tries": 10 }
# cat a.sh 
#!/bin/sh
device=/dev/cdc-wdm0

. /usr/share/libubox/jshn.sh

O="$(uqmi -s -d "$device" --get-pin-status)" 
echo "$O"
json_load "$O" | grep Failed
json_dump
json_load "$O"
json_dump

exit 0

grep Failed is the problem?

@dangowrt
Copy link
Member

Please try if this patch fixes it then

diff --git a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
index ad577ea317..8b8ba014ce 100755
--- a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
+++ b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
@@ -105,9 +105,9 @@ proto_qmi_setup() {
                        }
                }
        else
-               . /usr/share/libubox/jshn.sh
-               json_load "$(uqmi -s -d "$device" --get-pin-status)" 2>&1 | grep -q Failed &&
-                       json_load "$(uqmi -s -d "$device" --uim-get-sim-state)"
+               local pin_json="$(uqmi -s -d "$device" --get-pin-status)"
+               [ "${pin_json:0:1}" = "{" ] || pin_json="$(uqmi -s -d "$device" --uim-get-sim-state)"
+               json_load "$pin_json"
                json_get_var pin1_status pin1_status
                json_get_var pin1_verify_tries pin1_verify_tries
 

This should have the desired effect (and we can remove . /usr/share/libubox/jshn.sh because it's included in netifd-proto.sh anyway already)

@obsy
Copy link
Contributor Author

obsy commented Mar 24, 2022

Ok. it works. But looks very bad. Maybe like this:

pin_json="$(uqmi -s -d "$device" --get-pin-status)"
pin=$(echo "$pin_json" | jsonfilter -q -e '@.pin1_status')
[ -z "$pin" ] && pin_json="$(uqmi -s -d "$device" --uim-get-sim-state)"
 json_load "$pin_json"

Duplicate, but tests if it's really json.

@dangowrt
Copy link
Member

dangowrt commented Mar 24, 2022

How about

diff --git a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
index ad577ea317..c2c5fc1eca 100755
--- a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
+++ b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
@@ -105,10 +105,12 @@ proto_qmi_setup() {
                        }
                }
        else
-               . /usr/share/libubox/jshn.sh
-               json_load "$(uqmi -s -d "$device" --get-pin-status)" 2>&1 | grep -q Failed &&
-                       json_load "$(uqmi -s -d "$device" --uim-get-sim-state)"
+               json_load "$(uqmi -s -d "$device" --get-pin-status)"
                json_get_var pin1_status pin1_status
+               if [ -z "$pin1_status" ]; then
+                       json_load "$(uqmi -s -d "$device" --uim-get-sim-state)"
+                       json_get_var pin1_status pin1_status
+               fi
                json_get_var pin1_verify_tries pin1_verify_tries
 
                case "$pin1_status" in

That would avoid duplicate parsing and also avoid wildly checking for the first character of the replied string...

@obsy
Copy link
Contributor Author

obsy commented Mar 24, 2022

Ok.

jow- pushed a commit that referenced this issue Mar 24, 2022
Evaluating the return value of 'json_load' didn't work in the
intended way resulting in PIN status no longer being read on modems
where --get-pin-status doesn't fail.
Fix this by trying --get-pin-status first and checking if pin1_status
field exists in JSON, and if it doesn't try again with
--uim-get-sim-state.

Fixes: #9501
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this issue Mar 25, 2022
Evaluating the return value of 'json_load' didn't work in the
intended way resulting in PIN status no longer being read on modems
where --get-pin-status doesn't fail.
Fix this by trying --get-pin-status first and checking if pin1_status
field exists in JSON, and if it doesn't try again with
--uim-get-sim-state.

Fixes: openwrt#9501
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
jow- pushed a commit that referenced this issue Mar 27, 2022
Evaluating the return value of 'json_load' didn't work in the
intended way resulting in PIN status no longer being read on modems
where --get-pin-status doesn't fail.
Fix this by trying --get-pin-status first and checking if pin1_status
field exists in JSON, and if it doesn't try again with
--uim-get-sim-state.

Fixes: #9501
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
(cherry picked from commit ee7cb5e)
erdoukki pushed a commit to CyberMind-FR/openwrt that referenced this issue Aug 1, 2022
Evaluating the return value of 'json_load' didn't work in the
intended way resulting in PIN status no longer being read on modems
where --get-pin-status doesn't fail.
Fix this by trying --get-pin-status first and checking if pin1_status
field exists in JSON, and if it doesn't try again with
--uim-get-sim-state.

Fixes: openwrt#9501
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants