-
-
Save halms/70ac29a31878f8675366459a3a4b9fe2 to your computer and use it in GitHub Desktop.
Huawei Modem in LEDE using NCM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. /lib/functions.sh | |
. ../netifd-proto.sh | |
init_proto "$@" | |
proto_huawei_dhcp_init_config() { | |
available=1 | |
proto_config_add_string "device:device" | |
proto_config_add_string apn | |
proto_config_add_string user | |
proto_config_add_string password | |
proto_config_add_boolean defaultroute | |
proto_config_add_boolean peerdns | |
proto_config_add_int metric | |
} | |
proto_huawei_dhcp_setup() { | |
local config="$1" | |
local iface="$2" | |
local device apn user password defaultroute peerdns metric | |
json_get_vars device apn user password defaultroute peerdns metric | |
[ -n "$device" ] || { | |
echo "No control device specified" | |
proto_notify_error "$config" NO_DEVICE | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
[ -e "$device" ] || { | |
echo "Control device not valid" | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
[ -n "$apn" ] || { | |
echo "No APN specified" | |
proto_notify_error "$config" NO_APN | |
return 1 | |
} | |
echo -e "ATZ\r" >$device | |
sleep 5 | |
echo -e "AT^NDISDUP=1,1,\"$apn\",\"$user\",\"$password\"\r" >$device | |
sleep 5 | |
echo "Connected, starting DHCP on $iface" | |
proto_init_update "$iface" 1 | |
proto_send_update "$config" | |
json_init | |
json_add_string name "${config}_4" | |
json_add_string ifname "@$config" | |
json_add_string proto "dhcp" | |
[ -n "$defaultroute" ] && json_add_boolean defaultroute "$defaultroute" | |
[ -n "$peerdns" ] && json_add_boolean peerdns "$peerdns" | |
[ -n "$metric" ] && json_add_int metric "$metric" | |
ubus call network add_dynamic "$(json_dump)" | |
} | |
proto_huawei_dhcp_teardown() { | |
local config="$1" | |
local device | |
json_get_vars device | |
[ -n "$device" ] || { | |
echo "No control device specified" | |
proto_notify_error "$config" NO_DEVICE | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
[ -e "$device" ] || { | |
echo "Control device not valid" | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
echo "Stopping network" | |
echo -e "AT^NDISDUP=1,0\r" >$device | |
proto_init_update "*" 0 | |
proto_send_update "$config" | |
} | |
add_protocol huawei_dhcp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. /lib/functions.sh | |
. ../netifd-proto.sh | |
init_proto "$@" | |
proto_huawei_raw_init_config() { | |
available=1 | |
proto_config_add_string "device:device" | |
proto_config_add_string apn | |
proto_config_add_string user | |
proto_config_add_string password | |
} | |
proto_huawei_raw_setup() { | |
local config="$1" | |
local iface="$2" | |
local device apn user password | |
json_get_vars device apn user password | |
[ -n "$device" ] || { | |
echo "No control device specified" | |
proto_notify_error "$config" NO_DEVICE | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
[ -e "$device" ] || { | |
echo "Control device not valid" | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
[ -n "$apn" ] || { | |
echo "No APN specified" | |
proto_notify_error "$config" NO_APN | |
return 1 | |
} | |
echo -e "ATZ\r" >$device | |
sleep 5 | |
echo -e "AT^NDISDUP=1,1,\"$apn\",\"$user\",\"$password\"\r" >$device | |
sleep 5 | |
echo "Connected" | |
proto_init_update "$iface" 1 | |
proto_send_update "$config" | |
} | |
proto_huawei_raw_teardown() { | |
local config="$1" | |
local device | |
json_get_vars device | |
[ -n "$device" ] || { | |
echo "No control device specified" | |
proto_notify_error "$config" NO_DEVICE | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
[ -e "$device" ] || { | |
echo "Control device not valid" | |
proto_set_available "$config" 0 | |
return 1 | |
} | |
echo "Stopping network" | |
echo -e "AT^NDISDUP=1,0\r" >$device | |
proto_init_update "*" 0 | |
proto_send_update "$config" | |
} | |
add_protocol huawei_raw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment