From 27c9b64b6a910a15b0570ace528650b230faf1f2 Mon Sep 17 00:00:00 2001 From: XT-Martinez <32611135+XT-Martinez@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:39:22 +0800 Subject: [PATCH] Add config for 4G cell ID locking --- .../luci-static/resources/protocol/quectel.js | 25 ++++++++++++++++ wwan/app/quectel-cm/files/quectel.sh | 29 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/wwan/app/luci-proto-quectel/htdocs/luci-static/resources/protocol/quectel.js b/wwan/app/luci-proto-quectel/htdocs/luci-static/resources/protocol/quectel.js index 7f5deff..f70ab3a 100644 --- a/wwan/app/luci-proto-quectel/htdocs/luci-static/resources/protocol/quectel.js +++ b/wwan/app/luci-proto-quectel/htdocs/luci-static/resources/protocol/quectel.js @@ -155,5 +155,30 @@ return network.registerProtocol('quectel', { o.placeholder = '0'; o.datatype = 'uinteger'; o.depends('defaultroute', '1'); + + o = s.taboption('advanced', form.DynamicList, 'cell_lock_4g', _('4G Cell ID Lock')); + o.datatype = 'string'; + o.placeholder = _(','); + + o.validate = function(section_id, value) { + if (value === null || value === '') + return true; + + var parts = value.split(','); + if (parts.length !== 2) + return _('Must be two values separated by a comma(,)'); + + var isUnsignedInteger = function(str) { + return /^\d+$/.test(str); + }; + + if (!isUnsignedInteger(parts[0])) + return _('Invalid PCI!'); + + if (!isUnsignedInteger(parts[1])) + return _('Invalid EARFCN!'); + + return true; + }; } }); diff --git a/wwan/app/quectel-cm/files/quectel.sh b/wwan/app/quectel-cm/files/quectel.sh index 2072e61..82f3948 100644 --- a/wwan/app/quectel-cm/files/quectel.sh +++ b/wwan/app/quectel-cm/files/quectel.sh @@ -26,12 +26,13 @@ proto_quectel_init_config() { proto_config_add_boolean "sourcefilter" proto_config_add_boolean "delegate" proto_config_add_int "mtu" + proto_config_add_array 'cell_lock_4g:list(string)' proto_config_add_defaults } proto_quectel_setup() { local interface="$1" - local device apn apnv6 auth username password pincode delay pdptype pdnindex pdnindexv6 multiplexing + local device apn apnv6 auth username password pincode delay pdptype pdnindex pdnindexv6 multiplexing cell_lock_4g local dhcp dhcpv6 sourcefilter delegate mtu $PROTO_DEFAULT_OPTIONS local ip4table ip6table local pid zone @@ -45,6 +46,30 @@ proto_quectel_setup() { [ -n "$delay" ] || delay="5" sleep "$delay" + if json_is_a cell_lock_4g array; then + echo "4G Cell ID Locking" + json_select cell_lock_4g + idx=1 + cell_ids="" + + while json_is_a ${idx} string + do + json_get_var cell_lock $idx + pci=$(echo $cell_lock | cut -d',' -f1) + earfcn=$(echo $cell_lock | cut -d',' -f2) + cell_ids="$cell_ids,$earfcn,$pci" + idx=$(( idx + 1 )) + done + idx=$(( idx - 1 )) + + if [ "$idx" -gt 0 ]; then + cell_ids="${idx}${cell_ids}" + echo -e "AT+QNWLOCK=\"COMMON/4G\",${cell_ids}" | atinout - /dev/ttyUSB2 - + fi + else + echo -e "AT+QNWLOCK=\"COMMON/4G\",0" | atinout - /dev/ttyUSB2 - + fi + [ -n "$metric" ] || metric="0" [ -z "$ctl_device" ] || device="$ctl_device" @@ -119,6 +144,8 @@ proto_quectel_setup() { zone="$(fw3 -q network "$interface" 2>/dev/null)" if [ "$pdptype" = "ipv6" ] || [ "$pdptype" = "ipv4v6" ]; then + ip -6 addr flush dev $ifname6 + json_init json_add_string name "${interface}_6" json_add_string device "$ifname6"