aboutsummaryrefslogtreecommitdiffhomepage
path: root/IOBluetooth-Compat/IOBluetooth-Compat/IOBluetooth_Compat.h
blob: a06ed5f49a9149bdb4b278f5c6c91cb8da52f3b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//
//  IOBluetooth_Compat.h
//  IOBluetooth-Compat
//
//  Created by TCMac on 15/11/2013.
//  Original Header is (c) Apple Inc.
//

#import <Foundation/Foundation.h>
#import <IOBluetooth/IOBluetooth.h>
/*!	@typedef	IOBluetoothRFCOMMEvent
 @discussion	The events generated by an RFCOMM channel:
 
 <br>
 kIOBluetoothRFCOMMChannelEventTypeData:	new data.
 <br>
 kIOBluetoothRFCOMMChannelEventTypeFlowControlChanged: flow control changed.
 <br>
 kIOBluetoothRFCOMMChannelEventTypeClosed: channel terminated.
 <br>
 kIOBluetoothRFCOMMChannelEventTypeControlSignalsChanged: signals (like DTR, CTR) changed. (not yet supported)
 <br>
 kIOBluetoothRFCOMMChannelEventTypeWriteComplete:	write operation completed
 <br>
 kIOBluetoothRFCOMMChannelEventTypeQueueSpaceAvailable: more room in the RFCOMM channel output queue
 
 Obsolete Event types:
 
 <br>
 kIOBluetoothRFCOMMNewDataEvent:	new data.
 <br>
 kIOBluetoothRFCOMMFlowControlChangedEvent: flow control changed.
 <br>
 kIOBluetoothRFCOMMChannelTerminatedEvent: channel terminated.
 <br>
 kIOBluetoothRFCOMMControlSignalsChangedEvent: signals (like DTR, CTR) changed. (not yet supported)
 <br>
 
 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:
 
 <pre>
 
 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;
 }
 }
 
 </pre>
 
 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:
 
 <pre>
 
 IOBluetoothRFCOMMChannel *myOBJCChannel = [IOBluetoothRFCOMMChannel withRFCOMMChannelRef:rfcommChannel];
 
 </pre>
 */

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