// // IOBluetooth_Compat.h // IOBluetooth-Compat // // Created by TCMac on 15/11/2013. // Original Header is (c) Apple Inc. // #import #import /*! @typedef IOBluetoothRFCOMMEvent @discussion The events generated by an RFCOMM channel:
kIOBluetoothRFCOMMChannelEventTypeData: new data.
kIOBluetoothRFCOMMChannelEventTypeFlowControlChanged: flow control changed.
kIOBluetoothRFCOMMChannelEventTypeClosed: channel terminated.
kIOBluetoothRFCOMMChannelEventTypeControlSignalsChanged: signals (like DTR, CTR) changed. (not yet supported)
kIOBluetoothRFCOMMChannelEventTypeWriteComplete: write operation completed
kIOBluetoothRFCOMMChannelEventTypeQueueSpaceAvailable: more room in the RFCOMM channel output queue Obsolete Event types:
kIOBluetoothRFCOMMNewDataEvent: new data.
kIOBluetoothRFCOMMFlowControlChangedEvent: flow control changed.
kIOBluetoothRFCOMMChannelTerminatedEvent: channel terminated.
kIOBluetoothRFCOMMControlSignalsChangedEvent: signals (like DTR, CTR) changed. (not yet supported)
See the description of kIOBluetoothRFCOMMChannelEventTypeDataType and kIOBluetoothRFCOMMChannelEventTypeFlowControlChangedType for more information on these events. */ typedef enum IOBluetoothRFCOMMChannelEventType { // New event types added in 1.2 (Mac OS X 10.2.5) kIOBluetoothRFCOMMChannelEventTypeData = 0x0000, kIOBluetoothRFCOMMChannelEventTypeFlowControlChanged = 0x0001, kIOBluetoothRFCOMMChannelEventTypeClosed = 0x0002, kIOBluetoothRFCOMMChannelEventTypeOpenComplete = 0x0003, kIOBluetoothRFCOMMChannelEventTypeControlSignalsChanged = 0x0004, kIOBluetoothRFCOMMChannelEventTypeWriteComplete = 0x0005, kIOBluetoothRFCOMMChannelEventTypeQueueSpaceAvailable = 0x0006, // Obsolete Event names: kIOBluetoothRFCOMMNewDataEvent = 0x0000, kIOBluetoothRFCOMMFlowControlChangedEvent = 0x0001, kIOBluetoothRFCOMMChannelTerminatedEvent = 0x0002 } IOBluetoothRFCOMMChannelEventType; // This is to keep build build. Please use the new type, this is going to be deprecated typedef IOBluetoothRFCOMMChannelEventType IOBluetoothRFCOMMEvent; //-------------------------------------------------------------------------------------------------------------------------- /*! @typedef IOBluetoothRFCOMMDataBlock @discussion Associted to the kIOBluetoothRFCOMMNewDataEvent it carries a pointer and a size of the new incoming data. */ typedef struct IOBluetoothRFCOMMDataBlock { void *dataPtr; size_t dataSize; } IOBluetoothRFCOMMDataBlock; //-------------------------------------------------------------------------------------------------------------------------- /*! @typedef IOBluetoothRFCOMMFlowControlStatus @discussion Related to the kIOBluetoothRFCOMMFlowControlChangedEvent it carries the status of the flow control. For the first release of the APIs this event is generated only when flow control switches from OFF to ON. Future releases will support the switch from ON to OFF as well. */ typedef enum IOBluetoothRFCOMMFlowControlStatus { kIOBluetoothRFCOMMChannelFlowControlStatusIsOff = 0x0000, kIOBluetoothRFCOMMChannelFlowControlStatusIsOn = 0x0001 } IOBluetoothRFCOMMFlowControlStatus; //-------------------------------------------------------------------------------------------------------------------------- /*! @typedef IOBluetoothRFCOMMChannelEvent @discussion Structure that holds an RFCOMM event. */ typedef struct IOBluetoothRFCOMMChannelEvent { // Caution: You cannot add any more values here for binary compatibility reasons IOBluetoothRFCOMMChannelEventType eventType; union { // Caution: An element of this union cannot grow beyond 32 bytes in size for binary compatibility reasons. IOBluetoothRFCOMMDataBlock data; IOBluetoothRFCOMMFlowControlStatus flowStatus; IOBluetoothRFCOMMChannelRef terminatedChannel; void* writeRefCon; UInt8 padding[32]; // Old name, is going to be deprecated, use data instead IOBluetoothRFCOMMDataBlock newData; } u; IOReturn status; // Add new items above this comment. } IOBluetoothRFCOMMChannelEvent; @interface IOBluetooth_Compat : NSObject /*! @typedef IOBluetoothRFCOMMChannelIncomingEventListener @abstract Typedef for the RFCOMM channel event listener. @param rfcommChannel (IOBluetoothRFCOMMChannelRef) RFCOMM channel which received the events. @param refCon (void *) User-defined refCon provided upon registration. @param event (IOBluetoothRFCOMMChannelEvent) The type of event for this notification. @discussion This is the definition for the callback which will be invoked upon receiving data on a RFCOMM channel. For example an event listener function:
 
 void rfcommEventListener (IOBluetoothRFCOMMChannelRef rfcommChannel, void *refCon, IOBluetoothRFCOMMChannelEvent *event)
 {
 switch (event->eventType)
 {
 case kIOBluetoothRFCOMMNewDataEvent:
 // In thise case:
 // event->u.newData.dataPtr  is a pointer to the block of data received.
 // event->u.newData.dataSize is the size of the block of data.
 break;
 
 case kIOBluetoothRFCOMMFlowControlChangedEvent:
 // In thise case:
 // event->u.flowStatus       is the status of flow control (see IOBluetoothRFCOMMFlowControlStatus for current restrictions)
 break;
 
 case kIOBluetoothRFCOMMChannelTerminatedEvent:
 // In this case:
 // event->u.terminatedChannel is the channel that was terminated. It can be converted in an IOBluetoothRFCOMMChannel
 // object with [IOBluetoothRFCOMMChannel withRFCOMMChannelRef:]. (see below).
 break;
 }
 }
 
 
rfcommChannel is the channel that generated the event and it is the channel where the callback was generated. rfcommChannel is a IOBluetoothRFCOMMChannelRef reference, it can be converted in an Objective C IOBluetoothRFCOMMChannel object with:
 
 IOBluetoothRFCOMMChannel *myOBJCChannel = [IOBluetoothRFCOMMChannel withRFCOMMChannelRef:rfcommChannel];
 
 
*/ typedef void (*IOBluetoothRFCOMMChannelIncomingEventListener)(IOBluetoothRFCOMMChannelRef rfcommChannel, void *refCon, IOBluetoothRFCOMMChannelEvent *event); /*! @function IOBluetoothSDPServiceRecordGetRFCOMMChannelID @abstract Allows the discovery of the RFCOMM channel ID assigned to the service. @discussion This function will search through the ProtoclDescriptorList attribute to find an entry with the RFCOMM UUID (UUID16: 0x0003). If one is found, it gets the second element of the data element sequence and sets the rfcommChannelID pointer to it. The channel ID only gets set when kIOReturnSuccess is returned. @param serviceRecord The target IOBluetoothSDPServiceRecordRef @param rfcommChannelID A pointer to the location that will get the found RFCOMM channel ID. @result Returns kIOReturnSuccess if the channel ID is found. */ IOReturn IOBluetoothSDPServiceRecordGetRFCOMMChannelID(IOBluetoothSDPServiceRecordRef serviceRecord, BluetoothRFCOMMChannelID *channelID); /*! @function IOBluetoothRFCOMMChannelGetMTU @abstract @param rfcommChannel (IOBluetoothRFCOMMChannelRef) The channel reference @result Channel MTU size. @discussion Returns the length of the largest chunk of data that this channel can carry. If the caller wishes to use the write:length:sleep: api the length of the data can not be bigger than the channel MTU (maximum transfer unit). */ BluetoothRFCOMMMTU IOBluetoothRFCOMMChannelGetMTU( IOBluetoothRFCOMMChannelRef rfcommChannel ); /*! @function IOBluetoothRFCOMMChannelCloseChannel @param rfcommChannel (IOBluetoothRFCOMMChannelRef) The channel reference @result An error code value. 0 if successful. @discussion */ IOReturn IOBluetoothRFCOMMChannelCloseChannel(IOBluetoothRFCOMMChannelRef rfcommChannel); /*! @function IOBluetoothRFCOMMChannelWriteAsync @abstract Write data to a RFCOMM channel asynchronously. @param rfcommChannel (IOBluetoothRFCOMMChannelRef) The channel reference @param data is a pointer to the data buffer to be sent. @param length the length of the buffer to be sent (in bytes). @param refcon a NON NULL value that will be contained in the return event (once the data is sent). @result An error code value. 0 if successful. @discussion Sends data tough the channel. The number of bytes to be sent must not exceed the channel MTU. If the return value is an error condition none of the data was sent. NOTE: This function is only available in Mac OS X 10.2.5 (Bluetooth v1.2) or later. */ IOReturn IOBluetoothRFCOMMChannelWriteAsync(IOBluetoothRFCOMMChannelRef rfcommChannel, void *data, UInt16 length, void *refcon); /*! @function IOBluetoothDeviceOpenRFCOMMChannelAsync @abstract Opens a new RFCOMM channel to the target device. Returns immedialty after starting the opening process. @discussion This function will begin the process of opening a new RFCOMM channel to the target device. The baseband connection to the device will be opened if it is not open already. The RFCOMM channel open process will not complete until the client has registered an incoming data listener on the new channel. Because a new IOBluetoothL2CAPChannelRef will be created for the client as a result of this function, the client is responsible for releasing the resulting IOBluetoothL2CAPChannelRef (by calling IOBluetoothObjectRelease()). NOTE: This function is only available in Mac OS X 10.2.5 (Bluetooth v1.2) or later. @param btDevice The target IOBluetoothDeviceRef @param rfcommChannel A pointer to an IOBluetoothRFCOMMChannelRef to receive the RFCOMM channel requested to be opened. The rfcommChannel pointer will only be set if kIOReturnSuccess is returned. @param channelID The RFCOMM channel ID for the new channel. @param withEventListener a IOBluetoothRFCOMMChannelIncomingEventListener where to receive events regarding the channel (MUST be specified). @param refCon a refcon pointer (for the callback specified above). @result Returns kIOReturnSuccess if the open process was successfully started . */ IOReturn IOBluetoothDeviceOpenRFCOMMChannelAsync(IOBluetoothDeviceRef btDevice, IOBluetoothRFCOMMChannelRef *newChannel, BluetoothRFCOMMChannelID channelID, IOBluetoothRFCOMMChannelIncomingEventListener eventListener, void *refcon); @end