-
Notifications
You must be signed in to change notification settings - Fork 0
/
qnetinfo.sh
1624 lines (1399 loc) · 46.6 KB
/
qnetinfo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env sh
# Public domain, if used for good.
# =============================================================================
# QNETINFO
# -----------------------------------------------------------------------------
# Note: Extracts and represents network information from a Quectel LTE modem.
# Note: This only uses a minimal number POSIX shell features that are present
# in Busybox. Therefore the code is unfortunately pretty ugly and unoptimal,
# as no better options are available or readily usable. This stunt is
# performed by trained professional, please do not attempt to re-create.
set +x
set -e
set -m
qnetinfo__printf ()
{
local format="${1:?argument-required}"; shift
printf -- \
"$format\n\c" \
"$@"
}
qnetinfo__printf__inline ()
{
local format="${1:?argument-required}"; shift
printf -- \
"$format\c" \
"$@"
}
qnetinfo__printf__crlf ()
{
local format="${1:?argument-required}"; shift
printf -- \
"$format\r\n\c" \
"$@"
}
qnetinfo__prints ()
{
echo -n "$*"$'\n'
}
qnetinfo__prints__error ()
{
qnetinfo__printf \
'\e[91;1m%s\e[0m: %s.' 'error' "$*"
exit 1
}
qnetinfo__check__base10 ()
{
local p="${1:?argument-required}" P="${2:-}" v; eval 'v=${'"$p"'}'
local \
__v=${v#[-+]}
while [ -n "$__v" ]; do
__v=${__v#[0-9]}
case "$__v" in
[!0-9]*)
qnetinfo__printf \
'`%s'\''=`%s'\'' unexpected, expected numeric (base-10) value.' \
"${P:-$p}" "$v"
return 1
;;
esac
done
return 0
}
qnetinfo__check__base10__positive ()
{
if \
qnetinfo__check__base10 "$@"; then
local p="${1:?argument-required}" P="${2:-}" v; eval 'v=${'"$p"'}'
if [ "$v" -lt 0 ]; then
qnetinfo__printf \
'`%s'\''=`%s'\'' unacceptable, must be positive.' \
"${P:-$p}" "$v"
return 1
else
return 0
fi
else
return 1
fi
}
qnetinfo__check__base16 ()
{
local p="${1:?argument-required}" P="${2:-}" v; eval 'v=${'"$p"'}'
local \
__v=${v#0[Xx]}
while [ -n "$__v" ]; do
__v=${__v#[0-9A-Fa-f]}
case "$__v" in
[!0-9A-Fa-f]*)
qnetinfo__printf \
'`%s'\''=`%s'\'' unexpected, expected numeric (base-16) value.' \
"${P:-$p}" "$v"
return 1
;;
esac
done
return 0
}
TTYAWAIT__DEFAULT=250
TTYAWAIT=${TTYAWAIT:-$TTYAWAIT__DEFAULT}
# Note: This must be either `usbat' or `usbmodem', but the first is usually
# taken by the router.
TTYMODEM__DEFAULT='/dev/ttyUSB3'
TTYMODEM=${TTYMODEM:-$TTYMODEM__DEFAULT}
TTYSPEED__DEFAULT=9600
TTYSPEED=${TTYSPEED:-$TTYSPEED__DEFAULT}
MICROCOM__DEFAULT='microcom'
MICROCOM=$(which -- $MICROCOM__DEFAULT) || qnetinfo__prints__error \
"microcom \`$MICROCOM__DEFAULT' not found"
LOGLEVEL__DEFAULT=0
LOGLEVEL=${LOGLEVEL:-$LOGLEVEL__DEFAULT}
GRANDCLK=0
AWOLTIME__DEFAULT=60
AWOLTIME=${AWOLTIME:-$AWOLTIME__DEFAULT}
OUTATIME__DEFAULT=300
OUTATIME=${OUTATIME:-$OUTATIME__DEFAULT}
INTERVAL__DEFAULT=10
INTERVAL=${INTERVAL:-$INTERVAL__DEFAULT}
PARALLEL__DEFAULT=4
PARALLEL=${PARALLEL:-$PARALLEL__DEFAULT}
ANYMODEM__DEFAULT=0
ANYMODEM=${ANYMODEM:-$ANYMODEM__DEFAULT}
MAKEFIFO__DEFAULT='mkfifo'
MAKEFIFO=$(which -- $MAKEFIFO__DEFAULT) || qnetinfo__prints__error \
"makefifo \`$MAKEFIFO__DEFAULT' not found"
BURNFIFO__DEFAULT='rm'
BURNFIFO=$(which -- $BURNFIFO__DEFAULT) || qnetinfo__prints__error \
"burnfifo \`$BURNFIFO__DEFAULT' not found"
SORTTEXT__DEFAULT='sort'
SORTTEXT=$(which -- $SORTTEXT__DEFAULT) || qnetinfo__prints__error \
"sorttext \`$SORTTEXT__DEFAULT' not found"
GREPTEXT__DEFAULT='grep'
GREPTEXT=$(which -- $GREPTEXT__DEFAULT) || qnetinfo__prints__error \
"greptext \`$GREPTEXT__DEFAULT' not found"
UNIXTIME__DEFAULT='date'
UNIXTIME=$(which -- $UNIXTIME__DEFAULT) || qnetinfo__prints__error \
"unixtime \`$UNIXTIME__DEFAULT' not found"
for p in \
LOGLEVEL \
ANYMODEM; do
if ! qnetinfo__check__base10 "$p"; then
eval "$p"'=${'"$p"'__DEFAULT:?default-required}'
fi
done
for p in \
TTYAWAIT \
TTYSPEED \
AWOLTIME \
OUTATIME \
INTERVAL \
PARALLEL; do
if ! qnetinfo__check__base10__positive "$p"; then
eval "$p"'=${'"$p"'__DEFAULT:?default-required}'
fi
done
[ -c "$TTYMODEM" ] && \
[ -r "$TTYMODEM" ] && \
[ -w "$TTYMODEM" ] || qnetinfo__prints__error \
"ttymodem (\`$TTYMODEM') not a readable and writeable character special file"
[ -x "$MICROCOM" ] || qnetinfo__prints__error \
"microcom (\`$MICROCOM') not executable"
FIFO='/tmp/qnetinfo__fifo'
DISP='/tmp/qnetinfo__fifo__display'
qnetinfo__fifo__acquire ()
{
for fifo in "$FIFO" "$DISP"; do
if [ ! -p "$fifo" ]; then
$MAKEFIFO -- "$fifo"
fi
done
exec 5<> "$FIFO"
exec 6<> "$DISP"
}
qnetinfo__fifo__release ()
{
exec 6<&-
exec 5<&-
for fifo in "$FIFO" "$DISP"; do
if [ -p "$fifo" ]; then
$BURNFIFO -- "$fifo"
fi
done
}
qnetinfo__trap ()
{
qnetinfo__fifo__release
qnetinfo__printf '\rtrap: %s.' "${1:-???}"
exit
}
qnetinfo__trap__arm ()
{
trap "qnetinfo__trap '${1:?argument-required}'" "$1"
}
for signal in EXIT HUP QUIT INT ABRT ALRM TERM; do
qnetinfo__trap__arm "$signal"
done
qnetinfo__fifo__acquire
qnetinfo__time ()
{
$UNIXTIME -- '+%s'
}
qnetinfo__fmt__class__small__current='33'
qnetinfo__fmt__class__small__current__active='33'
qnetinfo__fmt__class__small__current__normal='37'
qnetinfo__fmt__class__small__current__absent='37;2'
qnetinfo__fmt__class__small__current__unknow='90;2'
qnetinfo__fmt__class__large__current='93'
qnetinfo__fmt__class__large__current__active='93;1'
qnetinfo__fmt__class__large__current__normal='37'
qnetinfo__fmt__class__large__current__absent='97;2'
qnetinfo__fmt__class__large__current__unknow='90;2'
qnetinfo__fmt__class__other__current='37'
qnetinfo__fmt__class__other__current__active='37;1'
qnetinfo__fmt__class__other__current__normal='37'
qnetinfo__fmt__class__other__current__absent='37;2'
qnetinfo__fmt__class__other__current__unknow='90;2'
qnetinfo__fmt__class__value__current='35;1'
qnetinfo__fmt__class__value__current__active='95;1'
qnetinfo__fmt__class__value__current__normal='96'
qnetinfo__fmt__class__value__current__absent='90'
qnetinfo__fmt__class__value__current__unknow='90'
qnetinfo__fmt__class__limit__current='35;2'
qnetinfo__fmt__class__limit__current__active='35;2'
qnetinfo__fmt__class__limit__current__normal='37;2'
qnetinfo__fmt__class__limit__current__absent='90'
qnetinfo__fmt__class__limit__current__unknow='90;2'
qnetinfo__fmt__class__value__average='95'
qnetinfo__fmt__class__limit__average='95;2'
qnetinfo__fmt__title ()
{
qnetinfo__printf '\e[37;4;1m%s\e[0m' "$*";
}
h__y () { qnetinfo__printf '\e[33''m%s\e[0m' "$*"; }
h__c () { qnetinfo__printf '\e[36;1m%s\e[0m' "$*"; }
h__Y () { qnetinfo__printf '\e[93''m%s\e[0m' "$*"; }
h__C () { qnetinfo__printf '\e[96;1m%s\e[0m' "$*"; }
h__W () { qnetinfo__printf '\e[97''m%s\e[0m' "$*"; }
qnetinfo__at__parameter__classify ()
{
local p="${1:?argument-required}"
case "$p" in
'v__common__s')
qnetinfo__prints 'small__current' ;;
'v__common__l')
qnetinfo__prints 'large__current' ;;
'v__common__o')
qnetinfo__prints 'other__current' ;;
'v__unique__s')
qnetinfo__prints "small__current__${p__unique__fmt__state:-unknow}" ;;
'v__unique__l')
qnetinfo__prints "large__current__${p__unique__fmt__state:-unknow}" ;;
'v__unique__o')
qnetinfo__prints "other__current__${p__unique__fmt__state:-unknow}" ;;
'p__common__min__'*'__avg'|\
'p__common__max__'*'__avg'|\
'p__unique__min__'*'__avg'|\
'p__unique__max__'*'__avg')
qnetinfo__prints 'limit__average' ;;
'p__common__min__'*|\
'p__common__max__'*)
qnetinfo__prints 'limit__current' ;;
'p__unique__min__'*|\
'p__unique__max__'*)
qnetinfo__prints "limit__current__${p__unique__fmt__state:-unknow}" ;;
'p__common__val__'*'__avg'|\
'p__unique__val__'*'__avg')
qnetinfo__prints 'value__average' ;;
'p__common__val__'*)
qnetinfo__prints 'value__current' ;;
'p__unique__val__'*)
qnetinfo__prints "value__current__${p__unique__fmt__state:-unknow}" ;;
esac
}
qnetinfo__fmt__str ()
{
local p="${1:?argument-required}" v qnetinfo__fmt__string qnetinfo__fmt__class; shift
eval \
qnetinfo__fmt__class='${qnetinfo__fmt__class__'"$(qnetinfo__at__parameter__classify "$p")"'}'
qnetinfo__fmt=$*
qnetinfo__printf '\e[%sm%s\e[0m' \
"$qnetinfo__fmt__class" "$qnetinfo__fmt"
}
qnetinfo__fmt__var ()
{
local p="${1:?argument-required}" v qnetinfo__fmt__string qnetinfo__fmt__class; eval v='${'"$p"'}'
if [ -z "$v" ]; then
local \
p__unique__fmt__state='unknow'
fi
eval \
qnetinfo__fmt__class='${qnetinfo__fmt__class__'"$(qnetinfo__at__parameter__classify "$p")"'}'
if [ -n "$v" ]; then
qnetinfo__fmt='%+03d'
else
qnetinfo__fmt='%3.3s'
fi
qnetinfo__printf '\e[%sm%s\e[0m' \
"$qnetinfo__fmt__class" "$qnetinfo__fmt"
}
qnetinfo__val__var ()
{
local p="${1:?argument-required}" v; eval v='${'"$p"'}'
if [ -n "$v" ]; then
qnetinfo__prints "$(( v > 99 ? 99 : v < -99 ? -99 : v ))"
else
case "$p" in
?'__unique__'*)
qnetinfo__prints '...' ;;
?'__common__'*|*)
qnetinfo__prints '???' ;;
esac
fi
}
__\
qnetinfo__mod ()
{
local q="${1:?argument-required}"
case "$q" in
0) qnetinfo__prints 'QPSK' ;;
1) qnetinfo__prints '16-QAM' ;;
2) qnetinfo__prints '64-QAM' ;;
3) qnetinfo__prints '256-QAM' ;;
*) qnetinfo__prints '???????' ;;
esac
}
# Note: These simply use 2nd degree polynomial fitting, scaled so that a signed
# 32-bit integer does not overflow. There is no floating point support, so
# the calculation is moved to fixed point domain. Also, by default values are
# rounded down, so the values shall be adjusted accordingly. It would be
# possible to further tweak the selected scale, but for this use case the extra
# precision provides no value.
qnetinfo__cqi__var ()
{
# Note: The UE must support 256-QAM, otherwise the reported modulation scheme
# is not valid. The lookup table, and thus the polynomials, are different
# otherwise.
local p="${1:?argument-required}" v; eval v='${'"$p"'}'
if [ $v -lt 16 ]; then
local q
# Note: -0.00719133807369102 * x**2 + 0.354347123464771 * x - 0.573626373626374
q=$(( \
( (-0x001d74aa ) * v * v \
+ ( 0x05ab67e0 ) * v \
+ (-0x012d92da ) ) \
/ ( 0x10000000 ) \
))
__qnetinfo__mod $q
fi
}
qnetinfo__mcs__var ()
{
# Note: Ditto.
local p="${1:?argument-required}" v; eval v='${'"$p"'}'
if [ $v -lt 32 ]; then
local q
if [ $v -lt 28 ]; then
# Note: -0.00223148499010568 * x**2 + 0.186686876342049 * x - 0.253694581280788
q=$(( \
( (-0x000923e1 ) * v * v \
+ ( 0x02fcab60 ) * v \
+ ( 0x03f0ddf4 ) ) \
/ ( 0x10000000 ) \
))
else
q=$(( v - 28 ))
fi
__qnetinfo__mod $q
fi
}
qnetinfo__chain ()
{
local IFS=','; set -- $*
# Note: Syntactic sugar. Allows input elements to be aligned.
if [ $# -gt 0 ]; then
while [ $# -gt 1 ]; do
qnetinfo__printf__inline \
'%s,' "${1:?argument-required}"
shift
done
qnetinfo__printf \
'%s' "${1:?argument-required}"
fi
}
export \
p__global__pci=
# E-UTRAN: Evolved Universal Terrestrial Radio Access Network
# MCC: Mobile Country Code ; 12 bits
# MNC: Mobile Network Code ; 8 bits or 12 bits
# TAC: Tracking Area Code ; 16 bits
# eNB: Evolved Node B
# eNBID: eNB Identifier ; 20 bits
# CellID: Cell Identifier ; 8 bits
# PLMN: Public Land Mobile Network ; MCC + MNC
# TAI: Tracking Area Identity ; MCC + MNC + TAC
# ECI: E-UTRAN Cell Identifier ; eNBID + CellID
# ECGI: E-UTRAN Cell Global Identifier ; MCC + MNC + eNBID + CellID
# CQI: Channel Quality Indicator
# 01 .. 03 QPSK ; ... when 256-QAM supported
# 04 .. 06 16-QAM
# 07 .. 11 64-QAM
# 12 .. 15 256-QAM
# MCS: Modulation Coding Scheme
# 00 .. 04, 28 QPSK ; ... ditto.
# 05 .. 10, 29 16-QAM
# 11 .. 19, 30 64-QAM
# 20 .. 27, 31 256-QAM
# RI: Rank Indicator
# PMI: Precoding Matrix Index
# PSS: Primary Synchronization Signal ; 0 .. 2
# SSS: Seconary Synchroniation Signal ; 0 .. 167 (LTE)
# PCI: Physical Cell Identity ; PSS + 3 * SSS
# CA: Channel Aggregation
# PCC: Primary Cell Carrier Component
# SCC: Secondary Cell Carrier Component
# Note: Parameters that are more or less common, or not reported for each
# cell, that the modem reports.
p__common__val=$(qnetinfo__chain \
'mcc' \
'mnc' \
'tac' \
'eci')
p__common__val__minmax=$(qnetinfo__chain \
'cqi' \
'mcs' \
'ri' \
'pmi' \
'tstp' \
'rsrp__ant0' \
'rsrp__ant1' \
'rsrp__ant2' \
'rsrp__ant3')
p__common__avg=$(qnetinfo__chain \
'cqi' \
'mcs' \
'ri' \
'pmi' \
'tstp' \
'rsrp__ant0' \
'rsrp__ant1' \
'rsrp__ant2' \
'rsrp__ant3')
# Note: Parameters that are unique for each given (physical) cell identifier.
p__unique__val__volatile=$(qnetinfo__chain \
'state' \
'state__lastseen')
p__unique__val=$(qnetinfo__chain \
'pci' \
'earfcn' \
'type' \
'bandwidth' \
'bandwidth__ul' \
'bandwidth__dl' \
'state' \
'state__lastseen')
p__unique__val__minmax=$(qnetinfo__chain \
'rsrq' \
'rsrp' \
'rssi' \
'sinr')
p__unique__avg=$(qnetinfo__chain \
'rsrq' \
'rsrp' \
'rssi' \
'sinr')
qnetinfo__calc__variable__avg ()
{
while [ $# -gt 0 ]; do
local p="${1:?argument-required}"
local p__name__avg="$p"'__avg'
local v v__avg; eval v='${'"$p"'}' v__avg='${'"$p__name__avg"':-${'"$p"'}}'
# Note: ``((v + 0.5) + (v__avg + 0.5)) / 2''.
if [ -n "$v" ]; then
: $(( $p__name__avg = ( v * 10 + v__avg * 10 + 10 ) / 20 ))
fi
shift
done
}
qnetinfo__trim__variable ()
{
local WSP=$' \t\v'
while [ $# -gt 0 ]; do
eval "$1"'=${'"$1"'##['"$WSP"']}'
eval "$1"'=${'"$1"'%%['"$WSP"']}'
shift
done
}
qnetinfo__at__parameter__argument ()
{
local IFS=':'; set -- $*
p="${1:?argument-required}"
p__modifier="${2:-}"
}
qnetinfo__at__parameter ()
{
local P="${1:?argument-required}" p v="${2:?argument-required}" v__translate=t
qnetinfo__trim__variable P v
qnetinfo__at__parameter__argument $P
eval unset \
'p__'"$p"
if [ -n "$p__modifier" ]; then
case "$p__modifier" in
*'~bypass-translate')
p__modifier=${p__modifier%~*}
v__translate=f
;;
esac
fi
case "${p__modifier:-default}" in
'default')
;;
'ignored')
[ $LOGLEVEL -gt 1 ] && qnetinfo__printf \
"$(h__y '%16s')"': `'"$(h__y '%s')"\'', ignored.' \
"$p" "$v"
return 0
;;
'numeric__base10'|'numeric')
qnetinfo__check__base10 "$p" "$P" || return 1
;;
'numeric__base16'|'numeric__hex')
qnetinfo__check__base16 "$p" "$P" || return 1
;;
*)
qnetinfo__printf \
'`%s'\'' unknown.' \
"$p__modifier"
return 2
;;
esac
if [ "$v" = '-' ]; then
qnetinfo__printf \
'`%s'\'' missing.' "$P" >&2
return 1
fi
[ $LOGLEVEL -gt 1 ] && qnetinfo__printf \
"$(h__Y '%16s')"': `'"$(h__W '%s')"\''.' \
"$p" "$v"
if [ "$v__translate" = 't' ]; then
case "$p" in
'bandwidth')
case "$v" in
6) v=1.4
;;
*) if [ $v -gt 6 ]; then
v=$(( v / 5 ))
fi
;;
esac
;;
'bandwidth__'*)
case "$v" in
0) v=1.4
;;
1) v=3
;;
*) if [ $v -gt 1 ]; then
v=$(( (v - 1) * 5 ))
fi
;;
esac
;;
'state')
case "$at__response__type" in
'PriCC')
case "$v" in
0) v='!' ;; # Not serving
1) v='R' ;; # Registered
*) v='?' ;;
esac
;;
'SecCC')
case "$v" in
0) v='!' ;; # Not configured
1) v='c' ;; # Configured, deactived
2) v='C' ;; # Configured, activated
*) v='?' ;;
esac
;;
*)
v='?'
;;
esac
;;
# Note: In theory `PCI 0' is valid. In practice, with this modem, it is
# errornously reported with incorrect (all zero) channel data. At the moment
# prefiltering is not implemented, sorry.
'pci')
if [ "$v" -le 0 ] \
|| [ "$v" -gt 503 ]; then
return 1
fi
;;
'tstp')
# Note: When the modem is "not transmitting" the value is reported as `-32768'.
# This goes a bit further and simply omit anything below -100 dB. This likely
# does not include all transmission given the value might remain invalid for
# long periods.
if [ "$v" -lt -1000 ]; then
return 1
fi
v=$(( (v + 5) / 10 ))
;;
'sinr')
# Note: As extracted from the firmware. This is unlike presented in any
# published documentation that either quote 3GPP or ``-20 + n / 5''.
v=$(( (-10 + v) * 2 ))
;;
esac
fi
eval \
'p__'"$p"="$v"
return 0
}
qnetinfo__at ()
{
local IFS=':'; set -- $*
local \
at__command="${1:?argument-required}"; shift
qnetinfo__trim__variable \
at__command
local IFS=','; set -- $*
# Note: If the subtype is passed as the first parameter, attach it to the input
# AT command.
case "$at__command" in
'+QENG'|'+QCAINFO'|'+QNETINFO')
local \
at__command__type="${1:?argument-required}"; shift
qnetinfo__trim__variable \
at__command__type
at__command="$at__command: $at__command__type";
esac
local \
at__response
local \
at__response__type
case "$at__command" in
'+QENG: "servingcell"')
at__response=$(qnetinfo__chain \
'state:ignored' \
'technology:ignored' \
'tdd:ignored' \
'mcc:numeric' \
'mnc:numeric' \
'eci:numeric__hex' \
'pci:numeric' \
'earfcn:numeric' \
'band:numeric' \
'bandwidth__ul:numeric' \
'bandwidth__dl:numeric' \
'tac:numeric__hex' \
'rsrp:numeric' \
'rsrq:numeric' \
'rssi:numeric' \
'sinr:numeric' \
'cqi:ignored' \
'tstp:numeric') # ... rest ignored.
;;
'+QENG: "neighbourcell '*'"')
at__response=$(qnetinfo__chain \
'technology:ignored' \
'earfcn:numeric' \
'pci:numeric' \
'rsrq:numeric' \
'rsrp:numeric' \
'rssi:numeric' \
'sinr:ignored')
;;
'+QCAINFO: "'*'"')
at__response=$(qnetinfo__chain \
'earfcn:numeric' \
'bandwidth:numeric' \
'band:ignored' \
'state:numeric' \
'pci:numeric' \
'rsrp:numeric' \
'rsrq:numeric' \
'rssi:numeric' \
'sinr:numeric~bypass-translate')
;;
'+QNETINFO: "servingcell"')
local \
at__command__subtype="{1:?argument-required}"; shift
case "$at__command__subtype" in
'"PCC"')
at__response__type='PriCC'
at__response=$(qnetinfo__chain \
'eci:numeric__hex' \
'pci:numeric' \
'earfcn:numeric' \
'band:ignored' \
'rsrp:numeric' \
'rsrq:numeric' \
'rssi:numeric' \
'sinr:ignored' \
'bandwidth__dl:numeric' \
'bandwidth__ul:numeric' \
'tac:ignored') # ... rest ignored.
;;
'"SCC"')
at__response__type='SecCC'
at__response=$(qnetinfo__chain \
'eci:numeric__hex' \
'pci:numeric' \
'earfcn:numeric' \
'band:ignored' \
'rsrp:numeric' \
'rsrq:numeric' \
'rssi:numeric' \
'sinr:ignored' \
'bandwidth__dl:numeric')
;;
*)
qnetinfo__printf \
'`%s'\'' unknown command (subtype), sorry.' \
"$at__command__subtype" >&2
return 1
;;
esac
;;
# CMR: Channel Measurement Report (?)
'+QNETINFO: "cmr"')
at__response=$(qnetinfo__chain \
'cqi:numeric' \
'mcs:numeric' \
'ri:numeric' \
'pmi:numeric')
;;
'+QRSRP')
at__response=$(qnetinfo__chain \
'rsrp__ant0:numeric' \
'rsrp__ant1:numeric' \
'rsrp__ant2:numeric' \
'rsrp__ant3:numeric')
;;
*)
qnetinfo__printf \
'`%s'\'' unknown command, sorry.' \
"$at__command" >&2
return 1
;;
esac
if [ -z "$at__response__type" ]; then
# Note: Presence of CA information will override any overlapping serving cell
# information. Namely, this type.
case "$at__command" in
'+'*': "servingcell"')
at__response__type='PriSC'
;;
# Note: Neighbour cell using the same carrier (band) as the primary cell.
'+'*': "neighbourcell intra"')
at__response__type='Intra'
;;
# Note: Neighbour cell using a different carrier.
'+'*': "neighbourcell inter"')
at__response__type='Inter'
;;
'+'*': "pcc"')
at__response__type='PriCC'
;;
'+'*': "scc"')
at__response__type='SecCC'
;;
esac
fi
local \
p__state__lastseen=$GRANDCLK
if [ -n "$at__response__type" ]; then
local \
p__type="$at__response__type"
fi
for p in $p__common__avg $p__common__val $p__unique__avg $p__unique__val; do
eval local \
'p__'"$p"
done
for P in $at__response; do
local \
qnetinfo__at__parameter__result=0
qnetinfo__at__parameter "$P" "${1:?argument-required}" || \
qnetinfo__at__parameter__result=$?; shift
case "$p__modifier" in
'ignored')
;;
'numeric'|'numeric__'*)
if [ $qnetinfo__at__parameter__result ]; then
eval local \
'p__'"$p"'__present'='y'
else
eval unset \
'p__'"$p"'__present'
fi
;;
esac
done
for p in $p__common__avg $p__common__val; do
eval local \
'__p'='$p__'"$p" \
'__p__present'='$p__'"$p"'__present'
if [ -z "$__p" ]; then
if [ -n "$__p__present" ]; then
# Note: If no value is defined, but the variable was set, the value is regarded
# invalid. Not only the current value is undefined, but the previously stored
# value, too.
eval unset \
'p__common__val__'"$p"
fi
else
eval \
'p__common__val__'"$p"='"$__p"'
fi
done
for p in $p__common__val__minmax; do
eval local \
'__p'='$p__'"$p" \
'__p__present'='$p__'"$p"'__present'
if [ -n "$__p" ]; then
# Note: Any minimum / maximum values are not touched, should the current value
# be ragarded as invalid.
eval local \
'__p__common__min'='"$p__common__min__'"$p"'"' \
'__p__common__max'='"$p__common__max__'"$p"'"'
if [ -z "$__p__common__min" ] \
|| [ "$__p__common__min" -gt "$__p" ]; then
eval \
'p__common__min__'"$p"='"$__p"'
fi
if [ -z "$__p__common__min" ] \
|| [ "$__p__common__max" -lt "$__p" ]; then
eval \
'p__common__max__'"$p"='"$__p"'
fi
fi
done
if [ -n "$p__pci" ]; then
eval local \
'__p__global__pci'='$p__global__pci__'"$p__pci"
if [ -z "$__p__global__pci" ]; then
eval \
'p__global__pci__'"$p__pci"='"$p__pci"'
p__global__pci=$(printf -- '%s\n%s' \
"$p__pci" \
"$p__global__pci" \
| $SORTTEXT -n)
fi
for p in $p__unique__val__volatile; do
eval local \
'p__'"$p"'__present'='*'
done
for p in $p__unique__avg $p__unique__val; do
eval local \
'__p'='$p__'"$p" \