| ||||||||
General Mac OS X Discussion General Apple and Mac OS X Discussion
|
| | LinkBack | Thread Tools | Display Modes |
(#1)
|
| Junior Member Posts: 19 Join Date: Feb 2009 Location: Australia | 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. BIOS A04 | USB Legacy Mode: OFF | Bluetooth: ON |
| | |
(#2)
|
| Guru Posts: 1,353 Join Date: Feb 2009 Location: Colorado, USA | 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 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. |
| | |
(#3)
|
(#4)
|
| Super Moderator Posts: 1,420 Join Date: Mar 2009 Location: United States | Quote:
![]() 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. Meklort's Blog | NBI Google Code Page | osx.mechdrew.com -- the best OSX installation guides | |
| | |
(#5)
|
(#6)
|
| Member Posts: 96 Join Date: Feb 2009 | Quote:
![]() 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. ![]() 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: )
| |
| | |
(#7)
|
| Guru Posts: 1,353 Join Date: Feb 2009 Location: Colorado, USA | 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));
} 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. |
| | |
(#8)
|
| Junior Member Posts: 19 Join Date: Feb 2009 Location: Australia | 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. BIOS A04 | USB Legacy Mode: OFF | Bluetooth: ON |
| | |
(#9)
|
| Guru Posts: 1,353 Join Date: Feb 2009 Location: Colorado, USA | 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 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. |
| | |
(#10)
|
| Junior Member Posts: 19 Join Date: Feb 2009 Location: Australia | 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! BIOS A04 | USB Legacy Mode: OFF | Bluetooth: ON |
| | |
![]() |
« Sleep not working after 10.5.8 upgrade
|
Wanted to say thank you to this forum and the software devs »
| Thread Tools | |
| Display Modes | |
| |
Copyright © 2008-2011 MyDellMini.com.













Linear Mode