General Mac OS X Discussion General Apple and Mac OS X Discussion

Reply
 
LinkBack Thread Tools Display Modes
  (#1) Old
Junior Member
 
Posts: 19
Join Date: Feb 2009
Location: Australia
Smile Possible aircraft-manager-util port for OSX - 04-02-2009, 08:26 AM

While reading these forums over the last few weeks, I've noticed that many peoples issues with OSX have been related to wifi and bluetooth, and the inability to properly turn these devices on without booting into Windows or Ubuntu.

I was hunting around for a better solution, and stumbled on this:
http://dell-mini.archive.canonical.com/ ... t11.tar.gz
This is the source code for Dell's aircraft-manager utility, which allows you to enable and disable the wireless and bluetooth devices.

I had a bit of a go at getting this to compile/run in some form on OSX, but I'm a bit of a n00b at this sort of thing.

However, from what I could tell, this is the Python code which did all the leg work. (extracted from 'aircraft-manager-util.in')

Code:
#!/usr/bin/python

import sys
#import dbus
import os
import portio


def getStatus (radio):
    # acquire permission for I/O
    portio.ioperm(0x68, 1, 1)
    portio.ioperm(0x6C, 1, 1)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x80) == 0):
            break

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xb0,0x6c)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xbb,0x68)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x01) != 0):
            break
    wstatus = portio.inb(0x68)
    print 'status = %x' % (wstatus)
        
    if (radio == 1):
        if (wstatus & 1 << 0):
            print 'Wifi on'
            x = 1
        else:
            print 'Wifi off'
            x = 0
        os.system ("echo " + str(x) + " > /tmp/wifi_status")

    if (radio == 2):
        if (wstatus & 1 << 1):
            print 'BT on'
            x = 1
        else:
            print 'BT off'
            x = 0
        os.system ("echo " + str(x) + " > /tmp/bt_status")

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xff,0x6c)


def powerControl (radio):
    # acquire permission for I/O
    portio.ioperm(0x68, 1, 1)
    portio.ioperm(0x6C, 1, 1)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x80) == 0):
            break

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xb0,0x6c)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xbb,0x68)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x01) != 0):
            break
    wstatus = portio.inb(0x68)
    print 'status = %x' % (wstatus)
        
    if (radio == 1):
        if (wstatus & 1 << 0):
            print 'Wifi on'
            x = 1
        else:
            print 'Wifi off'
            x = 3
    
    if (radio == 2):
        if (wstatus & 1 << 1):
            print 'BT on'
            x = 2
        else:
            print 'BT off'
            x = 4
    
    if (radio == 3):
        x = 1
    if (radio == 4):
        x = 2
    if (radio == 5):
        x = 3
    if (radio == 6):
        x = 4

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xff,0x6c)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x80) == 0):
            break

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xb1,0x6c)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xbb,0x68)

    new_wstatus = wstatus
    if (x == 1):
        new_wstatus = new_wstatus & 0xfe # turn off wireless
        #os.system("dbus-send --system --type=method_call --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.setWirelessEnabled boolean:false")
    if (x == 2):
        new_wstatus = new_wstatus & 0xfd # turn off bluetooth
    if (x == 3):
        new_wstatus = new_wstatus | 0x01 # turn on wireless
        #os.system("dbus-send --system --type=method_call --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.setWirelessEnabled boolean:true")
    if (x == 4):
        new_wstatus = new_wstatus | 0x02 # turn on bluetooth

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(new_wstatus,0x68)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xff,0x6c)

def ACControl (x):
    # acquire permission for I/O
    portio.ioperm(0x68, 1, 1)
    portio.ioperm(0x6C, 1, 1)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x80) == 0):
            break

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0x59,0x6c)

    if (x == 1):
        new_wstatus = 0xD7 # turn off AC charge
    if (x == 2):
        new_wstatus = 0xD8 # turn on AC charge

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(new_wstatus,0x68)

    while 1:
        status = portio.inb(0x6c)
        if ((status & 0x02) == 0):
            break
    portio.outb(0xff,0x6c)


#print str(sys.argv)
go = True

if len(sys.argv) < 3: 
    print "Too few arguments. Stopping."
    go = False

if go:
    objct = sys.argv[1]
    action = sys.argv[2]

    if objct == "BT": 
        if action == "on":
            print "\tTurning BT ON"
            powerControl(6)
        elif action == "off":
            print "\tTurning BT OFF"
            powerControl(4)
        elif action == "toggle":
            print "\tToggle BT"
            powerControl(2)
        elif action == "status":
            print "\tStatus BT"
            getStatus(2)
    elif objct == "WIFI": 
        if action == "on":
            print "\tTurning WIFI ON"
            powerControl(5)
        elif action == "off":
            print "\tTurning WIFI OFF"
            powerControl(3)
        elif action == "toggle":
            print "\tToggle WIFI"
            powerControl(1)
        elif action == "status":
            print "\tStatus WIFI"
            getStatus(1)
    elif objct == "AC_CHARGING": 
        if action == "on":
            print "\tTurning AC_CHARGING on"
            ACControl(2)
        if action == "off":
            print "\tTurning AC_CHARGING off"
            ACControl(1)
    elif objct == "RADIO": 
        if action == "toggle":
            powerControl(1)
            powerControl(2)

Note I've commented out the dbus calls, as I don't think they'd be needed in OSX, and I was at the point of trying to install PortIO module support for Python when I got stuck, and realized that I was in way over my head.

I had a quick look at coding in Objective C, then decided that it would probably simpler to put this out here on the forums, and someone else might know a better way to go about this.

Cheers, and keep up the good work!

Dave.


Dell Mini 9 | Mac OS X 10.5.7 | 2 GB RAM | 16 GB STEC SSD
BIOS A04 | USB Legacy Mode: OFF | Bluetooth: ON
Reply With Quote
  (#2) Old
Guru
 
meklort's Avatar
 
Posts: 1,353
Join Date: Feb 2009
Location: Colorado, USA
Send a message via AIM to meklort Send a message via MSN to meklort Send a message via Yahoo to meklort
Default Re: Possible aircraft-manager-util port for OSX - 04-02-2009, 08:40 AM

Thanks for taking the time to look into this. I'll look into writing a simple kext to toggle bluetooth and possibly wifi (and them mapping it to fn-2). Since I only have wifi, thats what it'll probably be initially.
I wont work on it till after the touchpad driver works better (I just have to fix a few bugs) and after the pref pane is done (I just have to figure out how to make preferences stay after reboot).


Dell Mini 9 | Mac OS X 10.6.5 | 2 GB RAM | 32 GB Buffalo SSD | BIOS A05
Dell Mini 10v | Mac OS X 10.6.5 | 1 GB RAM | 160 GB HDD | BIOS A06
My Blog | NetbookInstaller code repository | NetbookInstaller Website | Want a Lockerz.com invite? message me.
Reply With Quote
  (#3) Old
Junior Member
 
Posts: 10
Join Date: Mar 2009
Default Re: Possible aircraft-manager-util port for OSX - 04-02-2009, 11:12 AM

meklort,

Are you still thinking of including some way to turn off the special uses for the Fn-X keys (other than volume and brightness)?

I guess using the Fn keys would be good for some people, but turning off WiFi and/or bluetooth by pressing the wrong key by mistake can be a pain, so it would be great if this could be set as a preference somehow.

It would be even better if it was possible to remap the Fn-X keys to more useful/mac like stuff, like expose or dashboard.

Thanks
Reply With Quote
  (#4) Old
Super Moderator
 
bmcclure937's Avatar
 
Posts: 1,420
Join Date: Mar 2009
Location: United States
Send a message via AIM to bmcclure937
Default Re: Possible aircraft-manager-util port for OSX - 04-02-2009, 01:43 PM

Quote:
Originally Posted by acorral
<cut>
It would be even better if it was possible to remap the Fn-X keys to more useful/mac like stuff, like expose or dashboard.

Thanks
You can use the Fn keys to do these things... F11 and F12 (the Z and X key)

Back on topic : I think this would be a useful utility for those who have been wondering about turning off these features quickly when boarding a plane, etc.


 Mini 10v  | 2Gb RAM | 320 Gb HDD | Ubuntu 10.04 | OSX 10.6.3 | NBI .8.4RC1 | Chameleon Bullet Theme | BIOS A05 | USB Wake : OFF | USB Legacy : ON | No BlueTooth
Meklort's Blog | NBI Google Code Page | osx.mechdrew.com -- the best OSX installation guides
Reply With Quote
  (#5) Old
Senior Member
 
Posts: 203
Join Date: Feb 2009
Location: Arlington, MA
Default Re: Possible aircraft-manager-util port for OSX - 04-02-2009, 03:07 PM

Quote:
Originally Posted by un_dave
...from what I could tell, this is the Python code which did all the leg work. (extracted from 'aircraft-manager-util.in')
Dude, you are awesome.


Refurbished Cherry Red mini 9, 2 GB, RunCore 16 GB SSD; Bluetooth, 1.3 MP Webcam;
Mac OS X 10.6.7; NBI 20100616212351; BIOS A04, USB Legacy off
Reply With Quote
  (#6) Old
Member
 
Posts: 96
Join Date: Feb 2009
Default Re: Possible aircraft-manager-util port for OSX - 04-02-2009, 05:20 PM

Quote:
Originally Posted by un_dave
...
I had a bit of a go at getting this to compile/run in some form on OSX, but I'm a bit of a n00b at this sort of thing.

However, from what I could tell, this is the Python code which did all the leg work. (extracted from 'aircraft-manager-util.in')

Code:
import portio
...
Yeah ... I noticed that and was looking at it for the same reason.

I'm mostly a Perl programmer, so Python is "new", but once you've worked with them enough you can get to a "understand how its working and cut and paste" level in a language very quickly.

Basically the thing that keeps it from being a portio module which does the "heavy lifting" providing direct access to the IO ports (its in one of the usr/lib/python2.5/site-packages/ dir in the package if anyone is interested).
from the .egg-info of the module:

Code:
Metadata-Version: 1.0
Name: portio
Version: 0.1
Summary:  PortIO, low level port I/O for Linux x86

Home-page: http://portio.iriti.cnr.it
Author: Fabrizio Pollastri
Author-email: pollastri@iriti.cnr.it
License: http://www.gnu.org/licenses/gpl.txt
Description: PortIO is a Python front end to the low level functions provided by the
        C library on Linux 386 platforms for the hardware input and output ports:
        outb, outw, outl, outsb, outsw, outsl, outb_p, outw_p, outl_p, inb, inw,
        inl, insb, insw, insl, inb_p, inw_p, inl_p, ioperm, iopl.
        
        Before doing port I/O, it is mandatory to acquire proper privileges by
        calling ioperm or iopl. Otherwise you will get a segmentation fault.
Without porting THAT module to OSX, (and its a pre-compiles library that I haven't seen the course code for) the Python script won't work, so don't worry that you weren't able to make too much progress.

I was looking at trying to get the hang of Objective-C, since it seems like there are a number of "utilities" that could be bundled into an App to make lives easier (WiFi enable/disable, Bluetooth enable/disable, GPS on/off, a more advanced version of the Res Changer), but I'm afraid that learning, XCode, Objective-C and the OSX platform at once is one heck of a mouthful to try to swallow. :shock:


Dell Mini 9 - Cherry Red. 2GB RAM, 64GB RunCore, BlueTooth, 10.6.7 (working on getting 10.6.8 'working' )
Reply With Quote
  (#7) Old
Guru
 
meklort's Avatar
 
Posts: 1,353
Join Date: Feb 2009
Location: Colorado, USA
Send a message via AIM to meklort Send a message via MSN to meklort Send a message via Yahoo to meklort
Default Re: Possible aircraft-manager-util port for OSX - 04-02-2009, 05:40 PM

The kernel mode drivers in mac os x has access to inb and outb. It's jsut a ams call anyways. I don't know if usermode apps can use inb and outb. You cannot use objective c to write drivers (as far as I know, but I'm probably wrong). You can however write in objective c to make a program that talks to the kext and toggles it.

It's actually really easy to write a kext, so unless if someone else finds a better way / codes something first, I'll write one after I get the touchpad working better.

Copied form the PS2Controller kext...
Code:
#warning FIXME: use inb and outb from the kernel framework (2688371)
typedef unsigned short i386_ioport_t;
inline unsigned char inb(i386_ioport_t port)
{
    unsigned char datum;
    asm volatile("inb %1, %0" : "=a" (datum) : "d" (port));
    return(datum);
}

inline void outb(i386_ioport_t port, unsigned char datum)
{
    asm volatile("outb %0, %1" : : "a" (datum), "d" (port));
}
Oh, and its not that hard to learn osx, objective c and XCode in one swallow...


Dell Mini 9 | Mac OS X 10.6.5 | 2 GB RAM | 32 GB Buffalo SSD | BIOS A05
Dell Mini 10v | Mac OS X 10.6.5 | 1 GB RAM | 160 GB HDD | BIOS A06
My Blog | NetbookInstaller code repository | NetbookInstaller Website | Want a Lockerz.com invite? message me.
Reply With Quote
  (#8) Old
Junior Member
 
Posts: 19
Join Date: Feb 2009
Location: Australia
Default Re: Possible aircraft-manager-util port for OSX - 04-03-2009, 02:02 AM

I'm glad this has been of interest to more people than just me!

It sounds like development in this area is moving quickly, and unless I find myself with some free time, I'll leave this in the capable hands of meklort and the team.


Dell Mini 9 | Mac OS X 10.5.7 | 2 GB RAM | 16 GB STEC SSD
BIOS A04 | USB Legacy Mode: OFF | Bluetooth: ON
Reply With Quote
  (#9) Old
Guru
 
meklort's Avatar
 
Posts: 1,353
Join Date: Feb 2009
Location: Colorado, USA
Send a message via AIM to meklort Send a message via MSN to meklort Send a message via Yahoo to meklort
Default Re: Possible aircraft-manager-util port for OSX - 04-03-2009, 02:11 AM

I probably wont start working on it untill next week at the earliest.
and since I don't have bluetooth, it may by iffy as to getting it working (atleast easily).


Dell Mini 9 | Mac OS X 10.6.5 | 2 GB RAM | 32 GB Buffalo SSD | BIOS A05
Dell Mini 10v | Mac OS X 10.6.5 | 1 GB RAM | 160 GB HDD | BIOS A06
My Blog | NetbookInstaller code repository | NetbookInstaller Website | Want a Lockerz.com invite? message me.
Reply With Quote
  (#10) Old
Junior Member
 
Posts: 19
Join Date: Feb 2009
Location: Australia
Default Re: Possible aircraft-manager-util port for OSX - 04-03-2009, 02:54 AM

I'm very happy with my current solution of always on bluetooth and wireless, I'm just happy that it works, so I'm in no rush to see this implemented! I was just curious about this to help all those who frequent airports, it could be very useful for them, plus it makes the dell mini 9 osx solution more 'feature complete'.

Also, to to someone who's used to dealing with big businesses, and normal major software release cycles, week(s) is very fast!

If you need testers for the bluetooth, I'm sure you should have plenty of support here, or even, I bet, a few people who are willing to donate towards getting you a bluetooth module. I know I would be!


Dell Mini 9 | Mac OS X 10.5.7 | 2 GB RAM | 16 GB STEC SSD
BIOS A04 | USB Legacy Mode: OFF | Bluetooth: ON
Reply With Quote
Reply

« Sleep not working after 10.5.8 upgrade | Wanted to say thank you to this forum and the software devs »
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Copyright © 2008-2011 MyDellMini.com.