From a9bac6cda9bec9c36158234ad04b92b088c07bb8 Mon Sep 17 00:00:00 2001 From: Xiangfu Date: Wed, 4 Jul 2012 10:18:12 +0800 Subject: [PATCH] milkymist-files: files for configure m1 wireless gadget --- milkymist-files/files/m1-wireless.lua | 87 +++++++++++++++++++ milkymist-files/files/m1-wireless.sh | 59 +++++++++++++ .../qi_lb60/scripts/compile-openwrt-xburst.sh | 4 + xburst-tools/Makefile | 2 +- 4 files changed, 151 insertions(+), 1 deletion(-) create mode 100755 milkymist-files/files/m1-wireless.lua create mode 100755 milkymist-files/files/m1-wireless.sh diff --git a/milkymist-files/files/m1-wireless.lua b/milkymist-files/files/m1-wireless.lua new file mode 100755 index 0000000..f3c1f7d --- /dev/null +++ b/milkymist-files/files/m1-wireless.lua @@ -0,0 +1,87 @@ +#!/usr/bin/env lua + +local io = require "io" +local os = require "os" +local table = require "table" + +function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) +end + +function split(delim, text) + local list = {} + if string.len(text) <= 0 then + return list + end + delim = delim or "" + local pos = 1 + -- if delim matches empty string then it would give an endless loop + if string.find("", delim, 1) and delim ~= "" then + error("delim matches empty string!") + end + local first, last + while 1 do + if delim ~= "" then + first, last = string.find(text, delim, pos) + else + first, last = string.find(text, "%s+", pos) + if first == 1 then + pos = last+1 + first, last = string.find(text, "%s+", pos) + end + end + if first then -- found? + table.insert(list, string.sub(text, pos, first-1)) + pos = last+1 + else + table.insert(list, string.sub(text, pos)) + break + end + end + return list +end + +function exec(command) + local pp = io.popen(command) + local data = pp:read("*a") + pp:close() + + return data +end + +function iwscan(iface) + local siface = iface or "" + local cnt = exec("iwlist "..siface.." scan 2>/dev/null") + local iws = {} + + cnt = trim(cnt) + for i, l in pairs(split("\n Cell", cnt)) do + local ESSID = l:match("ESSID:\"(.-)\"") + if ESSID then + local Q = l:match("Quality[:=](.-)[ ]") + local A = l:match("Authentication Suites.- : (.-)\n") + local P = l:match("Pairwise Ciphers.- : (.-)\n") + + local enc + if not l:find("Encryption key:on") then + enc = "none" + else + local wpa = l:find("WPA Version 1") + local rsn = l:find("WPA2 Version 1") + if wpa and rsn then enc = "psk+psk2" + elseif rsn then enc = "psk2" + elseif wpa then enc = "psk" + else enc = "wep" end + end + + local r = Q .. "\t" .. ESSID .. "\t" .. enc + + table.insert(iws, r) + end + end + + return iws +end + +local t = iwscan("wlan0") +for k,v in pairs(t) do print(v) end diff --git a/milkymist-files/files/m1-wireless.sh b/milkymist-files/files/m1-wireless.sh new file mode 100755 index 0000000..a0d489e --- /dev/null +++ b/milkymist-files/files/m1-wireless.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +if [ "$1" == "set" ] && [ "$#" == "4" ]; then + uci delete network.wwan + uci commit wireless + + uci set network.wwan=interface + uci set network.wwan.proto=dhcp + uci commit wireless + + uci delete wireless.@wifi-iface[0] + uci commit wireless + + uci set wireless.@wifi-device[0].disabled=0 + uci add wireless wifi-iface > /dev/null 2>&1 + uci set wireless.@wifi-iface[0].device='radio0' + uci set wireless.@wifi-iface[0].network='wwan' + uci set wireless.@wifi-iface[0].mode='sta' + + #none for an open network, + #wep for WEP, + #psk for WPA-PSK, or + #psk2 + + uci set wireless.@wifi-iface[0].ssid=$2 + uci set wireless.@wifi-iface[0].key=$3 + uci set wireless.@wifi-iface[0].encryption=$4 + + uci commit wireless + wifi up > /dev/null 2>&1 + udhcpc -i wlan0 -b > /dev/null 2>&1 + + ifconfig wlan0 | grep "inet addr" + + exit 0 +fi + + +if [ "$1" == "get" ]; then + ifconfig -a | grep wlan0 > /dev/null 2>&1 + + if [ "$?" != "0" ]; then + iw phy phy0 interface add wlan0 type station + ifconfig wlan0 up + sleep 1 + fi + + /opt/m1-wireless.lua + + exit 0 +fi + +if [ "$1" == "status" ]; then + ifconfig wlan0 + + exit 0 +fi + +echo "Usage: $0 [get/set/status] PARAMS..." diff --git a/nanonote-files/data/qi_lb60/scripts/compile-openwrt-xburst.sh b/nanonote-files/data/qi_lb60/scripts/compile-openwrt-xburst.sh index 92a12a2..391f6e2 100755 --- a/nanonote-files/data/qi_lb60/scripts/compile-openwrt-xburst.sh +++ b/nanonote-files/data/qi_lb60/scripts/compile-openwrt-xburst.sh @@ -95,6 +95,10 @@ cp -a files/* ${IMAGES_DIR}/files/ (cd ${IMAGES_DIR} && \ grep -E "ERROR:\ package.*failed to build" BUILD_LOG | \ grep -v "package/kernel" > failed_packages.txt; \ + + if [ "$1" == "minimal" ]; then + cp failed_packages.txt /home/xiangfu/building/Nanonote/Ben/ + fi ) if [ "${MAKE_RET}" == "0" ]; then diff --git a/xburst-tools/Makefile b/xburst-tools/Makefile index ef6ad5d..6e35132 100644 --- a/xburst-tools/Makefile +++ b/xburst-tools/Makefile @@ -29,7 +29,7 @@ define Package/xburst-tools CATEGORY:=Utilities TITLE:=Xburst-Tools URL:=http://projects.qi-hardware.com/p/xburst-tools/ - DEPENDS:=+libusb +libusb-1.0 +confuse +libreadline + DEPENDS:=+libusb +libusb-1.0 +confuse +libreadline +libncurses endef define Package/xburst-tools/description