faf204012433525c1f9954e4c148252271267030
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Bluetooth / Interop / Interop.Bluetooth.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using Tizen.Network.Bluetooth;
19 using System.Runtime.InteropServices;
20
21 internal static partial class Interop
22 {
23     internal static partial class Bluetooth
24     {
25         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
26         internal delegate void StateChangedCallback(int result, int state, IntPtr userData);
27
28         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
29         internal delegate void NameChangedCallback(string deviceName, IntPtr userData);
30
31         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
32         internal delegate void VisibilityModeChangedCallback(int result, int visibility, IntPtr userData);
33
34         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
35         internal delegate void VisibilityDurationChangedCallback(int duration, IntPtr userData);
36
37         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
38         internal delegate void DiscoveryStateChangedCallback(int result, BluetoothDeviceDiscoveryState state, IntPtr deviceInfo, IntPtr userData);
39
40         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
41         internal delegate bool BondedDeviceCallback([MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceStruct device, IntPtr userData);
42
43         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
44         internal delegate void BondCreatedCallback(int result, [MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceStruct device, IntPtr userData);
45         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
46         internal delegate void BondDestroyedCallback(int result, string deviceAddress, IntPtr userData);
47         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
48         internal delegate void AuthorizationChangedCallback(int authorization, string deviceAddress, IntPtr userData);
49         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
50         internal delegate void ServiceSearchedCallback(int result, [MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceSdpStruct sdp, IntPtr userData);
51         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52         internal delegate void DeviceConnectionStateChangedCallback(bool connected, [MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceConnectionStruct device, IntPtr userData);
53         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
54         internal delegate bool ConnectedProfileCallback(int profile, IntPtr userData);
55
56         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
57         internal delegate void DataReceivedCallback([MarshalAs(UnmanagedType.Struct)]ref SocketDataStruct socketData, IntPtr userData);
58         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
59         internal delegate void SocketConnectionStateChangedCallback(int result, BluetoothSocketState connectionState, [MarshalAs(UnmanagedType.Struct)]ref SocketConnectionStruct socketConnection, IntPtr userData);
60
61         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
62         internal delegate void AudioConnectionStateChangedCallback(int result, bool connected, string deviceAddress, int profileType, IntPtr userData);
63
64         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
65         internal delegate void HidConnectionStateChangedCallback(int result, bool connected, string deviceAddress, IntPtr userData);
66
67         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
68         internal delegate void ConnectionRequestedCallback(string deviceAddress, IntPtr userData);
69         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
70         internal delegate void PushRequestedCallback(string file, long size, IntPtr userData);
71
72         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
73         internal delegate void TransferProgressCallback(string file, long size, int percent, IntPtr userData);
74         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
75         internal delegate void TransferFinishedCallback(int result, string file, long size, IntPtr userData);
76
77         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
78         internal delegate void PushRespondedCallback(int result, string deviceAddress, IntPtr userData);
79         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
80         internal delegate void PushProgressCallback(string file, long size, int percent, IntPtr userData);
81         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
82         internal delegate void PushFinishedCallback(int result, string deviceAddress, IntPtr userData);
83
84         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
85         internal delegate void TargetConnectionStateChangedCallback(bool connected, string deviceAddress, IntPtr userData);
86         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
87         internal delegate void EqualizerStateChangedCallback(int equalizer, IntPtr userData);
88         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
89         internal delegate void RepeatModeChangedCallback(int repeat, IntPtr userData);
90         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
91         internal delegate void ShuffleModeChangedCallback(int shuffle, IntPtr userData);
92         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
93         internal delegate void ScanModeChangedCallback(int scan, IntPtr userData);
94
95         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
96         internal delegate void ConnectionChangedCallback(int result, bool connected, string deviceAddress, IntPtr userData);
97         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
98         internal delegate void ClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, string value, int len, IntPtr userData);
99         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
100         internal delegate void GattClientRequestedCallback(int result, IntPtr handle, IntPtr userData);
101         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
102         internal delegate bool GattForEachCallback(int total, int index, IntPtr handle, IntPtr userData);
103
104         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_initialize")]
105         internal static extern int Initialize();
106         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_deinitialize")]
107         internal static extern int Deinitialize();
108
109         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_name")]
110         internal static extern int GetName(out string name);
111         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_name")]
112         internal static extern int SetName(string name);
113
114         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_state")]
115         internal static extern int GetState(out BluetoothState isActivated);
116         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_address")]
117         internal static extern int GetAddress(out string address);
118
119         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_visibility")]
120         internal static extern int GetVisibility(out int visibility, out int duration);
121
122         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_is_discovering")]
123         internal static extern int IsDiscovering(out bool isDiscovering);
124
125         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_start_device_discovery")]
126         internal static extern int StartDiscovery();
127         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_stop_device_discovery")]
128         internal static extern int StopDiscovery();
129
130         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_foreach_bonded_device")]
131         internal static extern int GetBondedDevices(BondedDeviceCallback bondedDeviceCb, IntPtr userData);
132
133         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_bonded_device_info")]
134         internal static extern int GetBondedDeviceByAddress(string deviceAddress, out IntPtr deviceInfo);
135         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_free_device_info")]
136         internal static extern int FreeDeviceInfo(BluetoothDeviceStruct deviceInfo);
137
138         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_is_service_used")]
139         internal static extern int IsServiceUsed(string serviceUuid, out bool used);
140
141         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_local_oob_data")]
142         internal static extern int GetOobData(out IntPtr hash, out IntPtr randomizer, out int hashLen, out int randomizerLen);
143         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_remote_oob_data")]
144         internal static extern int SetOobData(string deviceAddress, IntPtr hash, IntPtr randomizer, int hashLen, int randomizerLen);
145         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_remove_remote_oob_data")]
146         internal static extern int RemoveOobData(string deviceAddress);
147
148         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_state_changed_cb")]
149         internal static extern int SetStateChangedCallback(StateChangedCallback stateChangedCb, IntPtr userData);
150         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_state_changed_cb")]
151         internal static extern int UnsetStateChangedCallback();
152
153         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_name_changed_cb")]
154         internal static extern int SetNameChangedCallback(NameChangedCallback nameChangedCb, IntPtr userData);
155         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_name_changed_cb")]
156         internal static extern int UnsetNameChangedCallback();
157
158         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_visibility_mode_changed_cb")]
159         internal static extern int SetVisibilityModeChangedCallback(VisibilityModeChangedCallback visibilityChangedCb, IntPtr userData);
160         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_visibility_mode_changed_cb")]
161         internal static extern int UnsetVisibilityModeChangedCallback();
162
163         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_visibility_duration_changed_cb")]
164         internal static extern int SetVisibilityDurationChangedCallback(VisibilityDurationChangedCallback durationChangedCb, IntPtr userData);
165         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_visibility_duration_changed_cb")]
166         internal static extern int UnsetVisibilityDurationChangedCallback();
167
168         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_device_discovery_state_changed_cb")]
169         internal static extern int SetDiscoveryStateChangedCallback(DiscoveryStateChangedCallback discoveryChangedCb, IntPtr userData);
170         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_device_discovery_state_changed_cb")]
171         internal static extern int UnsetDiscoveryStateChangedCallback();
172
173         //Bluetooth Device
174         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_create_bond")]
175         internal static extern int CreateBond(string deviceAddress);
176         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_destroy_bond")]
177         internal static extern int DestroyBond(string deviceAddress);
178         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_cancel_bonding")]
179         internal static extern int CancelBonding();
180
181         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_alias")]
182         internal static extern int SetAlias(string deviceAddress, string alias);
183         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_authorization")]
184         internal static extern int SetAuthorization(string deviceAddress, int state);
185
186         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_get_service_mask_from_uuid_list")]
187         internal static extern int GetMaskFromUuid([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 1)] string[] uuids, int count, out BluetoothServiceClassType serviceMask);
188
189         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_start_service_search")]
190         internal static extern int StartServiceSearch(string deviceAddress);
191
192         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_foreach_connected_profiles")]
193         internal static extern int GetConnectedProfiles(string deviceAddress, ConnectedProfileCallback connectedProfileCb, IntPtr userData);
194         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_is_profile_connected")]
195         internal static extern int IsProfileConnected(string deviceAddress, int profile, out bool connectionStatus);
196
197         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_bond_created_cb")]
198         internal static extern int SetBondCreatedCallback(BondCreatedCallback bondCreatedCb, IntPtr userData);
199         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_bond_created_cb")]
200         internal static extern int UnsetBondCreatedCallback();
201
202         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_bond_destroyed_cb")]
203         internal static extern int SetBondDestroyedCallback(BondDestroyedCallback bondDestroyedCb, IntPtr userData);
204         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_bond_destroyed_cb")]
205         internal static extern int UnsetBondDestroyedCallback();
206
207         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_authorization_changed_cb")]
208         internal static extern int SetAuthorizationChangedCallback(AuthorizationChangedCallback authorizationChangedCb, IntPtr userData);
209         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_authorization_changed_cb")]
210         internal static extern int UnsetAuthorizationChangedCallback();
211
212         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_service_searched_cb")]
213         internal static extern int SetServiceSearchedCallback(ServiceSearchedCallback serviceSearchedCb, IntPtr userData);
214         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_service_searched_cb")]
215         internal static extern int UnsetServiceSearchedCallback();
216
217         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_connection_state_changed_cb")]
218         internal static extern int SetConnectionStateChangedCallback(DeviceConnectionStateChangedCallback connectionChangedCb, IntPtr userData);
219         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_connection_state_changed_cb")]
220         internal static extern int UnsetConnectionStateChangedCallback();
221
222         // Bluetooth LE Adapter
223
224         //Callback for event
225         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
226         internal delegate void AdapterLeScanResultChangedCallBack(int result,
227             [MarshalAs(UnmanagedType.Struct)]ref BluetoothLeScanDataStruct scanData, IntPtr userData);
228
229         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
230         public delegate void AdvertisingStateChangedCallBack(int result, IntPtr advertiserHandle,
231                             BluetoothLeAdvertisingState advertisingState, IntPtr userData);
232
233         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
234         public delegate void GattConnectionStateChangedCallBack(int result, bool connected,
235                                         string remoteAddress, IntPtr userData);
236
237         //Bluetooth Le Adapter Apis
238         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_start_scan")]
239         public static extern int StartScan(AdapterLeScanResultChangedCallBack callback, IntPtr userData);
240
241         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_scan")]
242         public static extern int StopScan();
243
244         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_uuids")]
245         public static extern int GetScanResultServiceUuid(ref BluetoothLeScanDataStruct scanData,
246             BluetoothLePacketType packetType, ref IntPtr uuids, ref int count);
247
248         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_device_name")]
249         public static extern int GetLeScanResultDeviceName(ref BluetoothLeScanDataStruct scanData,
250                             BluetoothLePacketType packetType, out string deviceName);
251
252         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_tx_power_level")]
253         public static extern int GetScanResultTxPowerLevel(ref BluetoothLeScanDataStruct scanData,
254                             BluetoothLePacketType packetType, out int txPowerLevel);
255
256         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_solicitation_uuids")]
257         public static extern int GetScaResultSvcSolicitationUuids(ref BluetoothLeScanDataStruct scanData,
258                             BluetoothLePacketType packetType, out IntPtr uuids, out int count);
259
260         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_data_list")]
261         public static extern int GetScanResultServiceDataList(ref BluetoothLeScanDataStruct scanData,
262                             BluetoothLePacketType PacketType, out IntPtr serviceDataArray, out int count);
263
264         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_free_service_data_list")]
265         public static extern int FreeServiceDataList(IntPtr serviceData, int count);
266
267         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_appearance")]
268         public static extern int GetScanResultAppearance(ref BluetoothLeScanDataStruct scanData,
269                             BluetoothLePacketType packetType, out int appearance);
270
271         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_manufacturer_data")]
272         public static extern int GetScanResultManufacturerData(ref BluetoothLeScanDataStruct scanData,
273                             BluetoothLePacketType packetType, out int manufId, out IntPtr manufData,
274                             out int manufDataLength);
275
276         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_connect")]
277         internal static extern int GattConnect(string deviceAddress, bool autoConnect);
278
279         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_disconnect")]
280         internal static extern int GattDisconnect(string deviceAddress);
281
282         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_connection_state_changed_cb")]
283         internal static extern int SetGattConnectionStateChangedCallback(
284             GattConnectionStateChangedCallBack gattConnectionChangedCb, IntPtr userData);
285
286         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_unset_connection_state_changed_cb")]
287         internal static extern int UnsetGattConnectionStateChangedCallback();
288
289         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_create_advertiser")]
290         public static extern int CreateAdvertiser(out IntPtr advertiserHandle);
291
292         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_destroy_advertiser")]
293         public static extern int DestroyAdvertiser(IntPtr advertiserHandle);
294
295         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_uuid")]
296         public static extern int AddAdvertisingServiceUuid(IntPtr advertiserHandle,
297                                     BluetoothLePacketType PacketType, string uuid);
298
299         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_solicitation_uuid")]
300         public static extern int AddAdvertisingServiceSolicitationUuid(IntPtr advertiserHandle,
301             BluetoothLePacketType PacketType, string uuid);
302
303         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_data")]
304         public static extern int AddAdvertisingServiceData(IntPtr advertiserHandle,
305             BluetoothLePacketType PacketType, string uuid, IntPtr serviceData, int serviceDatalength);
306
307         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_appearance")]
308         public static extern int SetAdvertisingAppearance(IntPtr advertiserHandle,
309                                     BluetoothLePacketType packetType, int appearance);
310
311         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_manufacturer_data")]
312         public static extern int AddAdvertisingManufData(IntPtr advertiserHandle, BluetoothLePacketType packetType,
313             int manufId, IntPtr manufData, int manufacturerDataLength);
314
315         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_device_name")]
316         public static extern int SetAdvertisingDeviceName(IntPtr advertiserHandle, BluetoothLePacketType packetType,
317                                                 bool includeName);
318
319         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_tx_power_level")]
320         public static extern int SetAdvertisingTxPowerLevel(IntPtr advertiserHandle, BluetoothLePacketType packetType,
321                                                 bool includePowerLevel);
322
323         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_clear_advertising_data")]
324         public static extern int ClearAdvertisingData(IntPtr advertiserHandle, BluetoothLePacketType packetType);
325
326         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_start_advertising_new")]
327         public static extern int BluetoothLeStartAdvertising(IntPtr advertiserHandle,
328                                          AdvertisingStateChangedCallBack callback, IntPtr userData);
329
330         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_advertising")]
331         public static extern int BluetoothLeStopAdvertising(IntPtr advertiserHandle);
332
333         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_mode")]
334         public static extern int SetAdvertisingMode(IntPtr advertiserHandle,
335                                         BluetoothLeAdvertisingMode advertisingMode);
336
337         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_connectable")]
338         public static extern int SetAdvertisingConnectable(IntPtr advertiserHandle,
339                                         bool connectable);
340
341         //Bluetooth Socket
342         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_create_rfcomm")]
343         internal static extern int CreateServerSocket(string serviceUuid, out int socketFd);
344         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_destroy_rfcomm")]
345         internal static extern int DestroyServerSocket(int socketFd);
346         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_listen_and_accept_rfcomm")]
347         internal static extern int Listen(int socketFd, int pendingConnections);
348         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_connect_rfcomm")]
349         internal static extern int ConnectSocket(string address, string serviceUuid);
350         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_disconnect_rfcomm")]
351         internal static extern int DisconnectSocket(int socketFd);
352         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_send_data")]
353         internal static extern int SendData(int socketFd, string data, int dataLength);
354         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_set_data_received_cb")]
355         internal static extern int SetDataReceivedCallback(DataReceivedCallback callback, IntPtr userData);
356         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_unset_data_received_cb")]
357         internal static extern int UnsetDataReceivedCallback();
358         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_set_connection_state_changed_cb")]
359         internal static extern int SetConnectionStateChangedCallback(SocketConnectionStateChangedCallback callback, IntPtr userData);
360         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_unset_connection_state_changed_cb")]
361         internal static extern int UnsetSocketConnectionStateChangedCallback();
362
363         // Bluetooth Audio
364         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_initialize")]
365         internal static extern int InitializeAudio();
366         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_deinitialize")]
367         internal static extern int DeinitializeAudio();
368
369         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_connect")]
370         internal static extern int Connect(string deviceAddress, int profileType);
371         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_disconnect")]
372         internal static extern int Disconnect(string deviceAddress, int profileType);
373
374         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_set_connection_state_changed_cb")]
375         internal static extern int SetAudioConnectionStateChangedCallback(AudioConnectionStateChangedCallback audioStateChangedCb, IntPtr userData);
376         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_unset_connection_state_changed_cb")]
377         internal static extern int UnsetAudioConnectionStateChangedCallback();
378
379         //Bluetooth Hid
380         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_initialize")]
381         internal static extern int InitializeHid(HidConnectionStateChangedCallback hidConnectionChangedCb, IntPtr userData);
382         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_deinitialize")]
383         internal static extern int DeinitializeHid();
384
385         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_connect")]
386         internal static extern int Connect(string deviceAddress);
387         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_disconnect")]
388         internal static extern int Disconnect(string deviceAddress);
389
390         // Bluetooth OPP
391         // Opp Server
392         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_server_initialize")]
393         internal static extern int InitializeOppServer(string deviceAddress, PushRequestedCallback pushRequestedCb, IntPtr userData);
394
395         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_server_deinitialize")]
396         internal static extern int DinitializeOppServer();
397
398         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_server_initialize_by_connection_request")]
399         internal static extern int InitializeOppServerCustom(string deviceAddress, ConnectionRequestedCallback connectionRequestedCb, IntPtr userData);
400
401         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_server_accept")]
402         internal static extern int OppServerAcceptPush(TransferProgressCallback transferProgressCb, TransferFinishedCallback transferFinishedCb, string name, IntPtr userData, out int transferId);
403
404         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_server_reject")]
405         internal static extern int OppServerRejectPush();
406
407         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_server_cancel_transfer")]
408         internal static extern int OppServerCancelTransfer(int transferId);
409
410         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_server_set_destination")]
411         internal static extern int OppServerSetDestinationPath(string path);
412
413         // Opp Client
414         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_client_initialize")]
415         internal static extern int InitializeOppClient();
416
417         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_client_dinitialize")]
418         internal static extern int DeinitializeOppClient();
419
420         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_client_add_file")]
421         internal static extern int OppClientAddFile(string filePath);
422
423         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_client_clear_files")]
424         internal static extern int OppClientClearFiles();
425
426         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_client_cancel_push")]
427         internal static extern int OppClientCancelPush();
428
429         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_opp_client_push_files")]
430         internal static extern int OppClientPushFile(string filePath, PushRespondedCallback pushRespondedCb, PushProgressCallback pushProgressCb, PushFinishedCallback pushFinishedCb, IntPtr userData);
431
432         //Bluetooth Avrcp
433         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_initialize")]
434         internal static extern int InitializeAvrcp(TargetConnectionStateChangedCallback targetStateChangedCb, IntPtr userData);
435         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_deinitialize")]
436         internal static extern int DeinitializeAvrcp();
437         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_equalizer_state")]
438         internal static extern int NotifyEqualizerState(int state);
439         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_repeat_mode")]
440         internal static extern int NotifyRepeatMode(int repeat);
441         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_shuffle_mode")]
442         internal static extern int NotifyShuffleMode(int shuffle);
443         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_scan_mode")]
444         internal static extern int NotifyScanMode(int scan);
445         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_player_state")]
446         internal static extern int NotifyPlayerState(int state);
447         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_position")]
448         internal static extern int NotifyCurrentPosition(uint position);
449         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_track")]
450         internal static extern int NotifyTrack(string title, string artist, string album, string genre, uint trackNum, uint totaltracks, uint duration);
451
452         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_equalizer_state_changed_cb")]
453         internal static extern int SetEqualizerStateChangedCallback(EqualizerStateChangedCallback equalizerStateChangedCb, IntPtr userData);
454         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_equalizer_state_changed_cb")]
455         internal static extern int UnsetEqualizerStateChangedCallback();
456         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_repeat_mode_changed_cb")]
457         internal static extern int SetRepeatModeChangedCallback(RepeatModeChangedCallback repeatModeChangedCb, IntPtr userData);
458         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_repeat_mode_changed_cb")]
459         internal static extern int UnsetRepeatModeChangedCallback();
460         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_shuffle_mode_changed_cb")]
461         internal static extern int SetShuffleModeChangedCallback(ShuffleModeChangedCallback shuffleModeChangedCb, IntPtr userData);
462         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_shuffle_mode_changed_cb")]
463         internal static extern int UnsetShuffleModeChangedCallback();
464         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_scan_mode_changed_cb")]
465         internal static extern int SetScanModeChangedCallback(ScanModeChangedCallback scanModeChangedCb, IntPtr userData);
466         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_scan_mode_changed_cb")]
467         internal static extern int UnsetScanModeChangedCallback();
468
469         // Bluetooth GATT
470
471         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
472         internal delegate bool BtGattForeachCallback(int total, int index, IntPtr gattHandle, IntPtr userData);
473
474         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
475         internal delegate void BtGattServerReadValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, int offset, IntPtr userData);
476
477         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
478         internal delegate void BtGattServerWriteValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, int offset, bool response_needed, byte[] value, int len, IntPtr userData);
479
480         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
481         internal delegate void BtClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, byte[] value, int len, IntPtr userData);
482
483         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
484         internal delegate void BtGattServerNotificationStateChangeCallback(bool notify, IntPtr serverHandle, IntPtr characteristicHandle, IntPtr userData);
485
486         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
487         internal delegate void BtGattServerNotificationSentCallback(int result, string clientAddress, IntPtr serverHandle, IntPtr characteristicHandle, bool completed, IntPtr userData);
488
489         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
490         internal delegate void BtGattClientRequestCompletedCallback(int result, IntPtr requestHandle, IntPtr userData);
491
492         // Gatt Attribute
493
494         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_destroy")]
495         internal static extern int BtGattDestroy(IntPtr gattHandle);
496
497         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_uuid")]
498         internal static extern int BtGattGetUuid(BluetoothGattAttributeHandle gattHandle, out string uuid);
499
500         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_value")]
501         internal static extern int BtGattGetValue(BluetoothGattAttributeHandle gattHandle, out IntPtr nativeValue, out int valueLength);
502
503         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_value")]
504         internal static extern int BtGattSetValue(BluetoothGattAttributeHandle gattHandle, byte[] value, int valueLength);
505
506         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_int_value")]
507         internal static extern int BtGattGetIntValue(BluetoothGattAttributeHandle gattHandle, int type, int offset, out int value);
508
509         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_int_value")]
510         internal static extern int BtGattSetIntValue(BluetoothGattAttributeHandle gattHandle, int type, int value, int offset);
511
512         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_float_value")]
513         internal static extern int BtGattGetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int offset, out float value);
514
515         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_float_value")]
516         internal static extern int BtGattSetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int mantissa, int exponent, int offset);
517
518         // GATT Descriptor
519
520         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_create")]
521         internal static extern int BtGattDescriptorCreate(string uuid, int permissions, byte[] value, int valueLength, out BluetoothGattAttributeHandle descriptorHandle);
522
523         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_get_permissions")]
524         internal static extern int BtGattDescriptorGetPermissions(BluetoothGattAttributeHandle descriptorHandle, out int permissions);
525
526         // GATT Characteristic
527
528         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_create")]
529         internal static extern int BtGattCharacteristicCreate(string uuid, int permissions, int properties, byte[] value, int valueLength, out BluetoothGattAttributeHandle characteristicHandle);
530
531         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_permissions")]
532         internal static extern int BtGattCharacteristicGetPermissions(BluetoothGattAttributeHandle characteristicHandle, out int permissions);
533
534         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_properties")]
535         internal static extern int BtGattCharacteristicGetProperties(BluetoothGattAttributeHandle characteristicHandle, out int properties);
536
537         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_set_properties")]
538         internal static extern int BtGattCharacteristicSetProperties(BluetoothGattAttributeHandle characteristicHandle, int properties);
539
540         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_write_type")]
541         internal static extern int BtGattCharacteristicGetWriteType(BluetoothGattAttributeHandle characteristicHandle, out int writeType);
542
543         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_set_write_type")]
544         internal static extern int BtGattCharacteristicSetWriteType(BluetoothGattAttributeHandle characteristicHandle, int writeType);
545
546         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_add_descriptor")]
547         internal static extern int BtGattCharacteristicAddDescriptor(BluetoothGattAttributeHandle characteristicHandle, BluetoothGattAttributeHandle descriptorHandle);
548
549         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_descriptor")]
550         internal static extern int BtGattCharacteristicGetDescriptor(BluetoothGattAttributeHandle characteristicHandle, string uuid, out BluetoothGattAttributeHandle descriptorHandle);
551
552         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_foreach_descriptors")]
553         internal static extern int BtGattCharacteristicForeachDescriptors(BluetoothGattAttributeHandle characteristicHandle, BtGattForeachCallback callback, IntPtr userData);
554
555         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_set_characteristic_value_changed_cb")]
556         internal static extern int BtGattClientSetCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle, BtClientCharacteristicValueChangedCallback cb, IntPtr userData);
557
558         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_unset_characteristic_value_changed_cb")]
559         internal static extern int BtGattClientUnsetCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle);
560
561         // GATT Service
562
563         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_create")]
564         internal static extern int BtGattServiceCreate(string uuid, int type, out BluetoothGattAttributeHandle serviceHandle);
565
566         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_add_characteristic")]
567         internal static extern int BtGattServiceAddCharacteristic(BluetoothGattAttributeHandle serviceHandle, BluetoothGattAttributeHandle characteristicHandle);
568
569         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_get_characteristic")]
570         internal static extern int BtGattServiceGetCharacteristic(BluetoothGattAttributeHandle serviceHandle, string uuid, out BluetoothGattAttributeHandle characteristicHandle);
571
572         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_foreach_characteristics")]
573         internal static extern int BtGattServiceForeachCharacteristics(BluetoothGattAttributeHandle serviceHandle, BtGattForeachCallback callback, IntPtr userData);
574
575         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_add_included_service")]
576         internal static extern int BtGattServiceAddIncludedService(BluetoothGattAttributeHandle serviceHandle, BluetoothGattAttributeHandle includedServiceHandle);
577
578         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_get_included_service")]
579         internal static extern int BtGattServiceGetIncludedService(BluetoothGattAttributeHandle serviceHandle, string uuid, out BluetoothGattAttributeHandle includedServiceHandle);
580
581         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_foreach_included_services")]
582         internal static extern int BtGattServiceForeachIncludedServices(BluetoothGattAttributeHandle serviceHandle, BtGattForeachCallback callback, IntPtr userData);
583
584         // GATT Client
585
586         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_destroy")]
587         internal static extern int BtGattClientDestroy(IntPtr clientHandle);
588
589         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_create")]
590         internal static extern int BtGattClientCreate(string remoteAddress, out BluetoothGattClientHandle clientHandle);
591
592         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_get_remote_address")]
593         internal static extern int BtGattClientGetRemoteAddress(BluetoothGattClientHandle clientHandle, out string remoteAddress);
594
595         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_get_service")]
596         internal static extern int BtGattClientGetService(BluetoothGattClientHandle clientHandle, string uuid, out BluetoothGattAttributeHandle serviceHandle);
597
598         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_foreach_services")]
599         internal static extern int BtGattClientForeachServices(BluetoothGattClientHandle clientHandle, BtGattForeachCallback callback, IntPtr userData);
600
601         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_read_value")]
602         internal static extern int BtGattClientReadValue(BluetoothGattAttributeHandle gattHandle, BtGattClientRequestCompletedCallback callback, IntPtr userData);
603
604         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_write_value")]
605         internal static extern int BtGattClientWriteValue(BluetoothGattAttributeHandle gattHandle, BtGattClientRequestCompletedCallback callback, IntPtr userData);
606
607         // GATT Server
608
609         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_destroy")]
610         internal static extern int BtGattServerDestroy(IntPtr serverHandle);
611
612         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_create")]
613         internal static extern int BtGattServerCreate(out BluetoothGattServerHandle serverHandle);
614
615         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_initialize")]
616         internal static extern int BtGattServerInitialize();
617
618         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_deinitialize")]
619         internal static extern int BtGattServerDeinitialize();
620
621         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_read_value_requested_cb")]
622         internal static extern int BtGattServerSetReadValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerReadValueRequestedCallback callback, IntPtr userData);
623
624         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_write_value_requested_cb")]
625         internal static extern int BtGattServerSetWriteValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerWriteValueRequestedCallback callback, IntPtr userData);
626
627         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_characteristic_notification_state_change_cb")]
628         internal static extern int BtGattServeSetNotificationStateChangeCallback(BluetoothGattAttributeHandle characteristicHandle, BtGattServerNotificationStateChangeCallback callback, IntPtr userData);
629
630         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_start")]
631         internal static extern int BtGattServerStart();
632
633         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_register_service")]
634         internal static extern int BtGattServerRegisterService(BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle serviceHandle);
635
636         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unregister_service")]
637         internal static extern int BtGattServerUnregisterService(BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle serviceHandle);
638
639         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unregister_all_services")]
640         internal static extern int BtGattServerUnregisterAllServices(BluetoothGattServerHandle serverHandle);
641
642         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_get_service")]
643         internal static extern int BtGattServerGetService(BluetoothGattServerHandle serverHandle, string uuid, out BluetoothGattAttributeHandle serviceHandle);
644
645         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_foreach_services")]
646         internal static extern int BtGattServerForeachServices(BluetoothGattServerHandle serverHandle, BtGattForeachCallback callback, IntPtr userData);
647
648         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_send_response")]
649         internal static extern int BtGattServerSendResponse(int requestId, int requestType, int offset, int status, byte[] value, int valueLen);
650
651         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_notify_characteristic_changed_value")]
652         internal static extern int BtGattServerNotify(BluetoothGattAttributeHandle characteristicHandle, BtGattServerNotificationSentCallback callback, string clientAddress, IntPtr userData);
653     }
654 }
655
656