Root/nanonote-TLWR11U/files/opt/m1-wireless.sh

1#!/bin/sh
2
3if [ "$1" == "set" ] && [ "$#" == "4" ]; then
4  uci delete network.wwan
5  uci set network.wwan=interface
6  uci set network.wwan.proto=dhcp
7
8  uci delete wireless.@wifi-iface[0]
9  uci set wireless.@wifi-device[0].disabled=0
10  uci add wireless wifi-iface > /dev/null 2>&1
11  uci set wireless.@wifi-iface[0].device='radio0'
12  uci set wireless.@wifi-iface[0].network='wwan'
13  uci set wireless.@wifi-iface[0].mode='sta'
14
15  #none for an open network,
16  #wep for WEP,
17  #psk for WPA-PSK, or
18  #psk2
19
20  uci set wireless.@wifi-iface[0].ssid=$2
21  uci set wireless.@wifi-iface[0].key=$3
22  uci set wireless.@wifi-iface[0].encryption=$4
23
24  uci commit network
25  uci commit wireless
26  ifup wwan
27  sleep 2
28  
29  exit 0
30fi
31
32
33if [ "$1" == "get" ]; then
34  ifconfig -a | grep wlan0 > /dev/null 2>&1
35
36  if [ "$?" != "0" ]; then
37    iw phy phy0 interface add wlan0 type station
38    ifconfig wlan0 up
39    sleep 1
40  fi
41  
42  /opt/m1-wireless.lua
43
44  exit 0
45fi
46
47if [ "$1" == "status" ]; then
48  sleep 1
49  IP=`ifconfig wlan0 2>/dev/null | grep "inet addr" | \
50      sed -e 's/^ *//g' | cut -d":" -f2 | cut -d" " -f1`
51  if [ "$?" != 0 ] || [ "${IP}" == "" ]; then
52    echo "Disconnected"
53    echo "0.0.0.0"
54    exit 1
55  fi
56  
57  ESSID=`iwconfig wlan0 2>/dev/null | grep ESSID | cut -d":" -f 2 | sed -e 's/\"//g'`
58  
59  echo "${ESSID}"
60  echo "${IP}"
61
62  exit 0
63fi
64
65echo "Usage: $0 [get/set/status] PARAMS..."
66exit 1
67

Archive Download this file



interactive