-
-
Save 0xFelix/18b3469adb8331100c34ae4ab6bc9fcf to your computer and use it in GitHub Desktop.
Huawei Modem in LEDE using NCM, copy file to /lib/netifd/proto and make it executable (chmod +x huawei_dhcp.sh), kmod-usb-net-huawei-cdc-ncm and usb-modeswitch need to be installed
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 pin | |
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 pin apn user password defaultroute peerdns metric | |
json_get_vars device pin 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 | |
[ -n "$pin" ] && { | |
echo -e "AT+CPIN=\"$pin\"\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
config interface 'wwan' | |
option proto 'huawei_dhcp' | |
option ifname 'wwan0' | |
option device '/dev/cdc-wdm0' | |
option pin '1234' | |
option apn 'internet' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment