I just got a Nokia 8801, and I am trying to send a Vcard using a modified version of the OBEXSampleSendVCard example.
In the code, I reach the point where i try to connect the device using:
OBEXConnect:maxPacketLength:eventSelector:selectorTarget:refCon
but the response I get from the callback seem to be buggy: the refCon and the status have the same value: [2F-FFF-1590/-1073752688/bfffd590
Have you experienced similar things with this callback?
Geraud
Details about the setup:
Phone: Nokia 8801
Environment: 1.33 G4 powerbook
OS X version: 10.4.5
Bluetooth:
* Manufacturer: Cambridge Silicon Radio
* Firmware Version: 2.1586
Here is most of the code:
call test: with a correct device/channelid
/* appcontroller.h */
#import .....
#define TEST_ADDRESS @"00-14-A7-75-F7-06"
#define TEST_CHANNEL_ID 1
@interface ApplicationController : NSObject {
BluetoothDeviceAddress _deviceAddress;
IOBluetoothDevice *_device;
IOBluetoothOBEXSession *session;
}
- (IBAction) test: (id) sender;
- (NSData*) makeVCard;
- (NSData*) makeHeaders;
-(void) OBEXNotify: (NSNumber*) stateObj status: (OBEXError) status ;
@end
/* appcontroller.m */
#define DECLARE_STATE(a,b) const int a##State= b;
DECLARE_STATE(OBEXStartOpen,1);
DECLARE_STATE(OBEXOpen,2);
DECLARE_STATE(OBEXConnect,3);
DECLARE_STATE(OBEXPut,4);
DECLARE_STATE(OBEXDisconnect,5);
#define LOG_RETAIN(a) NSLog(@"%s retainCount: [%u]",#a,[ a retainCount]);
NSNumber *OBEXState(int i ) {
return [[NSNumber numberWithInt:i] retain];
}
NSString *IOKitError(IOReturn error) {
return [NSString stringWithFormat:@"X-X-x/%d/x",err_get_system(error),err_get_sub(error),err_get_code(error),error,error];
}
@implementation ApplicationController
- (IBAction)test:(id)sender {
IOBluetoothNSStringToDeviceAddress(TEST_ADDRESS,&_deviceAddress );
_device= [[IOBluetoothDevice withAddress: &_deviceAddress] retain];
session= [[IOBluetoothOBEXSession alloc] initWithDevice: _device
channelID: TEST_CHANNEL_ID];
LOG_RETAIN(session);
LOG_RETAIN(_device);
[self OBEXNotify: OBEXState(OBEXStartOpenState) status: kOBEXSuccess];
}
- (void) OBEXNotify: (NSNumber*) stateObj status: (OBEXError) status {
LOG_RETAIN(session);
LOG_RETAIN(_device);
int state;
if(status != kOBEXSuccess ) {
NSLog(@"OBEXNotify:status: [%@]",IOKitError(status));
NSLog(@"~-~- ERROR -~-~");
return;
}
else {
NSLog(@"OBEXNotify: [%@] status: [%@]",stateObj,IOKitError(status));
state= [stateObj intValue];
}
OBEXError error= 0;
if(state==OBEXStartOpenState) {
error= [session openTransportConnection: @selector(OBEXNotify:status:)
selectorTarget: self
refCon: OBEXState(OBEXOpenState)];
}
else if(state==OBEXOpenState) {
error= [session OBEXConnect: kOBEXConnectFlagNone
maxPacketLength: 512
optionalHeaders: NULL
optionalHeadersLength: 0
eventSelector: @selector(OBEXNotify:status:)
selectorTarget: self
refCon: OBEXState(OBEXConnectState) ];
}
else if(state==OBEXConnectState) {
NSData *headers= [[self makeHeaders] retain];
NSData *vcard= [[self makeVCard] retain];
error= [session OBEXPut: YES
headersData: (void*) [headers bytes]
headersDataLength: [headers length]
bodyData: (void*) [vcard bytes]
bodyDataLength: [vcard length]
eventSelector: @selector(OBEXNotify:status:)
selectorTarget: self
refCon: OBEXState(OBEXPutState) ];
}
else if (state==OBEXPutState) {
}
NSLog(@"OBEXError: [%@]",IOKitError(error));
}