Privilege violation...
Privilege violation...
- Subject: Privilege violation...
- From: Carl Norum <email@hidden>
- Date: Mon, 8 Mar 2004 13:42:31 -0600
Hi there! I'm trying to get some simple bluetooth apps working. I've
written an L2CAP based text chat program for linux using the BlueZ
stack, and now I'm trying to write a Mac OS X client to connect to it
as well.
At the beginning everything works fine; I can connect to the linux box
using the following code:
NSAutoreleasePool *mainPool;
int main (int argc, const char *argv[])
{
IOBluetoothDevice *dev;
BluetoothDeviceAddress btAddr;
IOBluetoothL2CAPChannel *channel;
IOReturn err;
ChatDelegate *interface;
mainPool = [[NSAutoreleasePool alloc] init];
interface = [[ChatDelegate alloc] init];
IOBluetoothNSStringToDeviceAddress(@"00:04:76:C8:40:B0", &btAddr);
dev = [IOBluetoothDevice withAddress:&btAddr];
err = [dev openL2CAPChannel:kBluetoothL2CAPPSMRFCOMM
findExisting:FALSE newChannel:&channel];
NSLog(@"openL2CAPChannel: 0xx", err);
if (err != kIOReturnSuccess)
exit(0);
[channel setDelegate:interface];
[[NSRunLoop currentRunLoop] run];
return 0;
}
The ChatDelegate code looks like this:
- (void)sender:(IOBluetoothL2CAPChannel *)channel
{
IOReturn err;
senderPool = [[NSAutoreleasePool alloc] init];
char buffer[BUFFER_SIZE];
do {
fgets(buffer, BUFFER_SIZE, stdin);
err = [channel writeSync:buffer length:strlen(buffer) + 1];
NSLog(@"Return: 0x%0x String: %s", err, buffer);
} while (strcmp(buffer, ".\n") != 0);
[channel closeChannel];
[senderPool release];
[mainPool release];
exit(0);
}
- (void)l2capChannelData:(IOBluetoothL2CAPChannel*)l2capChannel
data:(void *)dataPointer length:(size_t)dataLength
{
NSLog(@"Data received");
printf(dataPointer);
if (strcmp(dataPointer, ".\n") == 0) {
[l2capChannel closeChannel];
[senderPool release];
[mainPool release];
exit(0);
}
}
- (void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*)l2capChannel
status:(IOReturn)error
{
NSLog(@"Channel Open Complete: 0x%x", error);
if (error == kIOReturnSuccess)
[NSThread detachNewThreadSelector:@selector(sender:)
toTarget:self withObject:l2capChannel];
}
The connection appears to work successfully - I get my @"Channel Open
Complete" message fine, and the linux box prints out "Connection
Accepted" after the accept() call returns. However, data sending and
receiving appears not to work. Anything I type in on the linux box
causes a successful return from send(), but nothing shows up on the Mac
via l2capChannel
Data:data:length. Likewise, anything entered on the
mac (from sender:) doesn't get sent - I get an IOReturn error
indicating kIOReturnNotPrivileged. Why does this happen? Any
thoughts, ideas, better ways to do this? I'm just getting started with
bluetooth, so I may be making terrible errors.
Thanks everyone!
--
Carl J Norum
Academic Director, IEEE NSS Student Branch
Final Year Electrical Engineering/Computer Science Student
University of Saskatchewan
Saskatoon, Canada
http://norum.homeunix.net/~carl/
_______________________________________________
bluetooth-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/bluetooth-dev
Do not post admin requests to the list. They will be ignored.