Author: titmuss
Date: Mon Jan  5 03:35:01 2009
New Revision: 3670

URL: http://svn.slimdevices.com?rev=3670&root=Jive&view=rev
Log:
 r3...@harrypotter (orig r3664):  titmuss | 2009-01-02 18:02:34 +0000
 Bug: N/A
 Description:
 Port changes r3560,r3652 to trunk.
 
 
 r3...@harrypotter (orig r3665):  titmuss | 2009-01-02 18:35:21 +0000
 Bug: N/A
 Description:
 Bump revision number to fix bad build.
 
 
 r3...@harrypotter (orig r3667):  titmuss | 2009-01-05 09:57:46 +0000
  r3...@harrypotter (orig r3666):  titmuss | 2009-01-05 09:51:50 +0000
  Bug: N/A
  Description:
  Fix wav playback, removing static.
  
  
 
 r3...@harrypotter (orig r3668):  titmuss | 2009-01-05 11:13:12 +0000
 Bug: N/A
 Description:
 Add /etc/init.d/squeezeplay script to make it easier to restart the 
squeezeplay 
 application. Options are:
 - start : to start SqueezePlay
 - stop : to kill SqueezePlay
 - stopwdog : to kill SqueezePlay, and start a watchdog process
 - restart : to restart SqueezePlay
 
 
 r3...@harrypotter (orig r3669):  titmuss | 2009-01-05 11:32:23 +0000
 Bug: N/A
 Description:
 Code clean up. Remove hardcoded eth0.
 
 

Added:
    
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/squeezeplay
Modified:
    7.4/branches/pango/   (props changed)
    
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/rcS
    
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/squeezeos-base-files_1.0.bb
    7.4/branches/pango/squeezeplay/src/squeezeplay/src/audio/decode/decode_pcm.c
    
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
    
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
    
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/jive/net/Wireless.lua
    7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/src/wireless.c

Propchange: 7.4/branches/pango/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Mon Jan  5 03:35:01 2009
@@ -3,8 +3,8 @@
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.1/trunk:2920
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.2/trunk:2921
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.3/private-branches/jive-refresh:3653
-bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.3/trunk:3658
-bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.4/trunk:3660
+bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.3/trunk:3666
+bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.4/trunk:3669
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:2013
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/SN:1083
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/scrolling:1378

Modified: 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/rcS
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/rcS?rev=3670&root=Jive&r1=3669&r2=3670&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/rcS 
(original)
+++ 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/rcS 
Mon Jan  5 03:35:01 2009
@@ -95,15 +95,5 @@
 done
 
 
-echo "Starting jive applications"
-export SDL_NOMOUSE=1
-export ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf
-export SQUEEZEPLAY_HOME=/etc/squeezeplay
-for dir in /media/*/squeezeplay; do
-       if [ -d $dir ]; then
-               LUA_PATH="$LUA_PATH;$dir/?.lua"
-       fi
-done
-export LUA_PATH
-
-(cd /usr/bin; /usr/bin/jive &)
+# Start squeezeplay
+/etc/init.d/squeezeplay start

Added: 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/squeezeplay
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/squeezeplay?rev=3670&root=Jive&view=auto
==============================================================================
--- 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/squeezeplay
 (added)
+++ 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/files/squeezeplay
 Mon Jan  5 03:35:01 2009
@@ -1,0 +1,48 @@
+#!/bin/sh
+
+case "$1" in
+    start)
+       echo "Starting SqueezePlay"
+
+       export SDL_NOMOUSE=1
+       export ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf
+       export SQUEEZEPLAY_HOME=/etc/squeezeplay
+
+       # Add extensions on media eg SD card to lua path
+       for dir in /media/*/squeezeplay; do
+               if [ -d $dir ]; then
+                       LUA_PATH="$LUA_PATH;$dir/?.lua"
+               fi
+       done
+       export LUA_PATH
+
+       cd /usr/bin
+       /usr/bin/jive &
+       ;;
+
+    stop)
+       echo "Stopping SqueezePlay"
+
+       killall -q jive
+       ;;
+
+    stopwdog)
+       echo "Stopping SqueezePlay (keeping watchdog alive)"
+
+       killall -q jive
+       sleep 2
+       watchdog -t 2 /dev/watchdog
+       ;;
+
+    restart)
+       $0 stop
+       sleep 2
+       $0 start
+       ;;
+
+    *)
+       echo "Usage: $0 {start|stop|stopwdog|restart}"
+       exit 1
+esac
+
+exit 0

Modified: 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/squeezeos-base-files_1.0.bb
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/squeezeos-base-files_1.0.bb?rev=3670&root=Jive&r1=3669&r2=3670&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/squeezeos-base-files_1.0.bb
 (original)
+++ 
7.4/branches/pango/squeezeos/poky/meta-squeezeos/packages/base-files/squeezeos-base-files_1.0.bb
 Mon Jan  5 03:35:01 2009
@@ -3,7 +3,7 @@
 PRIORITY = "required"
 LICENSE = "GPL"
 
-PR = "r21"
+PR = "r23"
 
 SRC_URI = " \
        file://85-mtd.rules \
@@ -32,6 +32,7 @@
        file://rcS.local.example \
        file://services \
        file://shadow \
+       file://squeezeplay \
        file://suspend \
        file://udhcpc_action \
        file://wlan \
@@ -76,6 +77,7 @@
        install -m 0644 ${WORKDIR}/inetd.conf ${D}${sysconfdir}/inetd.conf
        install -m 0644 ${WORKDIR}/inittab ${D}${sysconfdir}/inittab
        install -m 0755 ${WORKDIR}/rcS ${D}${sysconfdir}/init.d/rcS
+       install -m 0755 ${WORKDIR}/squeezeplay 
${D}${sysconfdir}/init.d/squeezeplay
        install -m 0755 ${WORKDIR}/wlan ${D}${sysconfdir}/init.d/wlan
        install -m 0755 ${WORKDIR}/suspend ${D}${sysconfdir}/init.d/suspend
        install -m 0644 ${WORKDIR}/issue ${D}${sysconfdir}/issue

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/src/audio/decode/decode_pcm.c
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/audio/decode/decode_pcm.c?rev=3670&root=Jive&r1=3669&r2=3670&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeplay/src/squeezeplay/src/audio/decode/decode_pcm.c 
(original)
+++ 
7.4/branches/pango/squeezeplay/src/squeezeplay/src/audio/decode/decode_pcm.c 
Mon Jan  5 03:35:01 2009
@@ -40,106 +40,35 @@
 
 
 static sample_t pcm_read8bitBE(u8_t *pos) { 
-       sample_t sample;
-       struct { s32_t sign_extend:8; } s;
-
-       /* XXXX: REVIEW */
-
-       sample = *pos;
-
-       sample = s.sign_extend = sample;
-       return sample << 24;
+       return (sample_t) (*pos << 24);
 }
 
-
 static sample_t pcm_read8bitLE(u8_t *pos) { 
-       sample_t sample;
-       struct { s32_t sign_extend:8; } s;
-
-       /* XXXX: REVIEW */
-
-       sample = *pos;
-
-       sample = s.sign_extend = sample;
-       return sample << 24;
+       return (sample_t) (*pos << 24);
 }
 
-
 static sample_t pcm_read16bitBE(u8_t *pos) { 
-       sample_t sample;
-       struct { s32_t sign_extend:16; } s;
-
-       /* XXXX: REVIEW */
-
-       sample = *pos++ << 8;
-       sample = *pos;
-
-       sample = s.sign_extend = sample;
-       return sample << 16;
+       return (sample_t) (*pos << 24) | (*++pos << 16);
 }
 
-
 static sample_t pcm_read16bitLE(u8_t *pos) {
-       sample_t sample;
-       struct { s32_t sign_extend:16; } s;
-
-       sample = *pos++;
-       sample = *pos << 8;
-
-       sample = s.sign_extend = sample;
-       return sample << 16;
+       return (sample_t) (*pos << 16) | (*++pos << 24);
 }
 
-
-static sample_t pcm_read24bitBE(u8_t *pos) { 
-       sample_t sample;
-       struct { s32_t sign_extend:24; } s;
-
-       /* XXXX: REVIEW */
-
-       sample = *pos++ << 16;
-       sample |= *pos++ << 8;
-       sample |= *pos;
-
-       sample = s.sign_extend = sample;
-       return sample << 8;
+static sample_t pcm_read24bitBE(u8_t *pos) {
+       return (sample_t) (*pos << 24) | (*++pos << 16) | (*++pos << 8);
 }
 
-
-static sample_t pcm_read24bitLE(u8_t *pos) { 
-       sample_t sample;
-       struct { s32_t sign_extend:24; } s;
-
-       sample = *pos++;
-       sample |= *pos++ << 8;
-       sample |= *pos << 16;
-
-       sample = s.sign_extend = sample;
-       return sample << 8;
+static sample_t pcm_read24bitLE(u8_t *pos) {
+       return (sample_t) (*pos << 8) | (*++pos << 16) | (*++pos << 24);
 }
 
-
-static sample_t pcm_read32bitBE(u8_t *pos) { 
-       sample_t sample;
-       struct { s32_t sign_extend:32; } s;
-
-       /* XXXX: REVIEW */
-
-       sample = *pos++ << 24;
-       sample |= *pos++ << 16;
-       sample |= *pos++ << 8;
-       sample |= *pos;
-
-       sample = s.sign_extend = sample;
-       return sample;
+static sample_t pcm_read32bitBE(u8_t *pos) {
+       return (sample_t) (*pos << 24) | (*++pos << 16) | (*++pos << 8) | 
(*++pos);
 }
 
-
 static sample_t pcm_read32bitLE(u8_t *pos) { 
-       sample_t sample;
-
-       sample = *((s32_t *)(void *)pos);
-       return sample;
+       return *((sample_t *)(void *)pos);
 }
 
 

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua?rev=3670&root=Jive&r1=3669&r2=3670&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
 (original)
+++ 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
 Mon Jan  5 03:35:01 2009
@@ -32,6 +32,7 @@
                                      _mtd = {},
                                      _size = {},
                                      _checksum = "",
+                                     _boardVersion = "",
                              })
 
        return obj
@@ -50,6 +51,13 @@
 
        callback(false, "UPDATE_DOWNLOAD", "")
 
+       -- parse the board revision
+       t, err = self:parseCpuInfo()
+       if not t then
+               log:warn("parseCpuInfo failed")
+               return nil, err
+       end
+
        -- parse the flash devices
        t, err = self:parseMtd()
        if not t then
@@ -57,15 +65,6 @@
                return nil, err
        end
                            
-       -- parse the kernel version
-       self._zImageExtraVersion = "zImage-P7"
-       self._mtd[self._zImageExtraVersion] = self._mtd["zImage"]
-       t, err = self:parseVersion()
-       if not t then
-               log:warn("parseVersion failed")
-               return nil, err
-       end
-
        -- disable VOL+ on boot
        t, err = self:fw_setenv({ sw7 = "" })
        if not t then
@@ -74,7 +73,7 @@
        end
 
        -- erase flash
-       t, err = self:flashErase(self._zImageExtraVersion)
+       t, err = self:flashErase("zImage")
        if not t then
                log:warn("flash kernel failed")
                return nil, err
@@ -96,7 +95,7 @@
        callback(false, "UPDATE_VERIFY")
 
        -- checksum kernel
-       t, err = self:checksum(self._zImageExtraVersion)
+       t, err = self:checksum("zImage")
        if not t then
                log:warn("flash checksum failed")
                return nil, err
@@ -187,6 +186,9 @@
                               elseif action == "checksum" then
                                       -- store checksum
                                       self._checksum = self._checksum .. chunk
+
+                              elseif action == "board.version" then
+                                      self._boardVersion = self._boardVersion 
.. chunk
                               end
 
                               return 1
@@ -209,9 +211,9 @@
 
                       if type(chunk) == "table" then
                               -- new file
-                              if chunk.filename == self._zImageExtraVersion 
then
+                              if string.match(chunk.filename, "^zImage") then
                                       -- kernel
-                                      part = self._zImageExtraVersion
+                                      part = "zImage"
 
                               elseif chunk.filename == "root.cramfs" then
                                       -- cramfs
@@ -221,6 +223,9 @@
                                       -- md5 checksums
                                       action = "checksum"
 
+                              elseif chunk.filename == "board.version" then
+                                      action = "board.version"
+
                               else
                                       action = nil
                               end
@@ -228,6 +233,11 @@
 
                               -- open file handle
                               if part ~= nil then
+                                      if not self:verifyPlatformRevision() then
+                                              self.sinkErr = "Incompatible 
firmware"
+                                              return nil
+                                      end
+
                                       action = "store"
                                       length = 0
 
@@ -244,6 +254,56 @@
                       -- should never get here
                       return nil
               end
+end
+
+
+-- utility function to parse /dev/cpuinfo
+function parseCpuInfo(self)
+       local fh, err = io.open("/proc/cpuinfo")
+       if fh == nil then
+               return fh, err
+       end
+
+       while true do
+               local line = fh:read()
+               if line == nil then
+                       break
+               end
+
+               if string.match(line, "Hardware") then
+                       self._platform = string.lower(string.match(line, 
".+:%s+([^%s]+)"))
+               elseif string.match(line, "Revision") then
+                       self._revision = tonumber(string.match(line, 
".+:%s+([^%s]+)"))
+               end
+
+       end
+       fh:close()
+
+       return 1
+end
+
+
+function verifyPlatformRevision(self)
+       for platform, revision in string.gmatch(self._boardVersion, 
"(%a+):(%d+)") do
+               platform = string.lower(platform)
+               revision = tonumber(revision)
+
+               if string.match(platform, self._platform)
+                       and revision == self._revision then
+                               return true
+               end
+       end
+
+       -- backwards compatibility for initial jive boards
+       if self._boardVersion == ""
+               and self._platform == "jive"
+               and self._revision == 0 then
+               return true
+       end
+
+       log:warn("Firmware is not compatible with ", self._platform, ":", 
self._revision)
+
+       return false
 end
 
 
@@ -303,36 +363,6 @@
 end
 
 
--- parse kernel extraversion
-function parseVersion(self)
-
-       local fh, err = io.open("/proc/version")
-       if fh == nil then
-               return fh, err
-       end
-
-       local version = fh:read("*all")
-       fh:close()
-
-       local extraversion = string.match(version, "Linux version 
[%d%.]+(%-[^%s]+)") or ""
-
-       -- backwards compatibility
-       if extraversion == "-P4" then
-               extraversion = ""
-       end
-
-       log:info("extraversion=", extraversion)
-
-       -- select kernel to use
-       self._zImageExtraVersion = "zImage" .. extraversion
-       self._mtd[self._zImageExtraVersion] = self._mtd["zImage"]
-
-       Task:yield(true)
-
-       return 1
-end
-
-
 -- update bootloader environment
 function fw_setenv(self, variables)
        local cmd = { "/usr/sbin/fw_setenv" }
@@ -410,16 +440,16 @@
                        end
                        Task:yield(true)
                end
-
-               if self.sinkErr then
-                       log:info("sinkErr=", self.sinkErr)
-                       return false, self.sinkErr
-               end
-
-               return true
        else
                return false, "Unsupported url scheme"
        end
+
+       if self.sinkErr then
+               log:info("sinkErr=", self.sinkErr)
+               return false, self.sinkErr
+       end
+
+       return true
 end
 
 

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua?rev=3670&root=Jive&r1=3669&r2=3670&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
 (original)
+++ 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
 Mon Jan  5 03:35:01 2009
@@ -32,6 +32,7 @@
                _file = {},
                _size = {},
                _checksum = "",
+               _boardVersion = "",
        })
 
        return obj
@@ -51,6 +52,13 @@
 function _upgrade(self)
 
        self._callback(false, "UPDATE_DOWNLOAD", "")
+
+       -- parse the board revision
+       t, err = self:parseCpuInfo()
+       if not t then
+               log:warn("parseCpuInfo failed")
+               return nil, err
+       end
 
        -- remove old image
        self:rmvol("kernel_bak")
@@ -96,6 +104,48 @@
 end
 
 
+-- utility function to parse /dev/cpuinfo
+function parseCpuInfo(self)
+       local fh, err = io.open("/proc/cpuinfo")
+       if fh == nil then
+               return fh, err
+       end
+
+       while true do
+               local line = fh:read()
+               if line == nil then
+                       break
+               end
+
+               if string.match(line, "Hardware") then
+                       self._platform = string.lower(string.match(line, 
".+:%s+([^%s]+)"))
+               elseif string.match(line, "Revision") then
+                       self._revision = tonumber(string.match(line, 
".+:%s+([^%s]+)"))
+               end
+
+       end
+       fh:close()
+
+       return 1
+end
+
+
+function verifyPlatformRevision(self)
+       for platform, revision in string.gmatch(self._boardVersion, 
"(%a+):(%d+)") do
+               platform = string.lower(platform)
+               revision = tonumber(revision)
+
+               if string.match(platform, self._platform)
+                       and revision == self._revision then
+                               return true
+               end
+       end
+
+       log:warn("Firmware is not compatible with ", self._platform, ":", 
self._revision)
+
+       return false
+ end
+
 -- utility function to parse /dev/mtd
 function parseMtd(self)
        local mtd = {}
@@ -174,6 +224,10 @@
                        elseif _action == "checksum" then
                                -- store checksum
                                self._checksum = self._checksum .. chunk
+
+                       elseif _action == "board.version" then
+                               self._boardVersion = self._boardVersion .. chunk
+
                        end
                        return 1
                end
@@ -195,6 +249,11 @@
                        local filename = chunk.filename
 
                        if string.match(filename, "^zImage") then
+                               if not self:verifyPlatformRevision() then
+                                       self.sinkErr = "Incompatible firmware"
+                                       return nil
+                               end
+
                                _action = "store"
                                _fhsink, err = self:updatevol("kernel_upg", 
filename, chunk.uncompressed_size)
                                if not _fhsink then
@@ -202,6 +261,11 @@
                                end
 
                        elseif filename == "root.cramfs" then
+                               if not self:verifyPlatformRevision() then
+                                       self.sinkErr = "Incompatible firmware"
+                                       return nil
+                               end
+
                                _action = "store"
                                _fhsink = self:updatevol("cramfs_upg", 
filename, chunk.uncompressed_size)
                                if not _fhsink then
@@ -210,6 +274,9 @@
 
                        elseif filename == "upgrade.md5" then
                                _action = "checksum"
+
+                       elseif chunk.filename == "board.version" then
+                               _action = "board.version"
 
                        else
                                -- ignore file
@@ -279,12 +346,12 @@
                        end
                        Task:yield(true)
                end
-
-               if self.sinkErr then
-                       error(self.sinkErr, 0)
-               end
        else
                error("Unsupported url scheme", 0)
+       end
+
+       if self.sinkErr then
+               error(self.sinkErr, 0)
        end
 end
 

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/jive/net/Wireless.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/jive/net/Wireless.lua?rev=3670&root=Jive&r1=3669&r2=3670&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/jive/net/Wireless.lua
 (original)
+++ 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/share/jive/net/Wireless.lua
 Mon Jan  5 03:35:01 2009
@@ -574,7 +574,7 @@
        end
 
        local err
-       self.t_sock, err = wireless:open()
+       self.t_sock, err = wireless:open("eth0")
        if err then
                log:warn(err)
 

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/src/wireless.c
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/src/wireless.c?rev=3670&root=Jive&r1=3669&r2=3670&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/src/wireless.c 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay_squeezeos/src/wireless.c Mon 
Jan  5 03:35:01 2009
@@ -17,25 +17,26 @@
 
 
 struct wlan_data {
+       char *iface;
        struct wpa_ctrl *ctrl;
        int fd;
 };
 
 
 static int jive_net_wpa_ctrl_open(lua_State *L) {
-       const char *ctrl_path;
+       char ctrl_path[PATH_MAX];
        struct wlan_data *data;
        int err;
 
        /* stack is:
-        * 1: JiveWPA
-        * 2: ctrl_path
+        * 1: Wireless class
+        * 2: iface
         */
 
-       // FIXME allow variable control path
-       ctrl_path = "/var/run/wpa_supplicant/eth0";
-
        data = lua_newuserdata(L, sizeof(struct wlan_data));
+
+       data->iface = strdup(lua_tostring(L, 2));
+       sprintf(ctrl_path, "/var/run/wpa_supplicant/%s", data->iface);
 
        data->ctrl = wpa_ctrl_open(ctrl_path);
        if (data->ctrl == NULL) {
@@ -90,6 +91,11 @@
                data->fd = 0;
        }
 
+       if (data->iface) {
+               free(data->iface);
+               data->iface = 0;
+       }
+
        return 0;
 }
 
@@ -187,7 +193,7 @@
                return 2;
        }
 
-       strncpy(wrq.ifr_ifrn.ifrn_name, "eth0", IFNAMSIZ);
+       strncpy(wrq.ifr_ifrn.ifrn_name, data->iface, IFNAMSIZ);
        wrq.u.power.flags = 0;
 
        if (ioctl(data->fd, SIOCGIWPOWER, &wrq) < 0) {
@@ -219,7 +225,7 @@
                return 2;
        }
 
-       strncpy(wrq.ifr_ifrn.ifrn_name, "eth0", IFNAMSIZ);
+       strncpy(wrq.ifr_ifrn.ifrn_name, data->iface, IFNAMSIZ);
 
        if (lua_toboolean(L, 2)) {
                wrq.u.power.disabled = 0;

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins

Reply via email to