2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Tizen.Network.Bluetooth;
19 using System.Runtime.InteropServices;
21 internal static partial class Interop
23 internal static partial class Bluetooth
25 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
26 internal delegate void StateChangedCallback(int result, int state, IntPtr userData);
28 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
29 internal delegate void NameChangedCallback(string deviceName, IntPtr userData);
31 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
32 internal delegate void VisibilityModeChangedCallback(int result, int visibility, IntPtr userData);
34 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
35 internal delegate void VisibilityDurationChangedCallback(int duration, IntPtr userData);
37 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
38 internal delegate void DiscoveryStateChangedCallback(int result, BluetoothDeviceDiscoveryState state, IntPtr deviceInfo, IntPtr userData);
40 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
41 internal delegate bool BondedDeviceCallback([MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceStruct device, IntPtr userData);
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);
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);
61 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
62 internal delegate void AudioConnectionStateChangedCallback(int result, bool connected, string deviceAddress, int profileType, IntPtr userData);
64 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
65 internal delegate void HidConnectionStateChangedCallback(int result, bool connected, string deviceAddress, IntPtr userData);
67 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
68 internal delegate void TargetConnectionStateChangedCallback(bool connected, string deviceAddress, IntPtr userData);
69 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
70 internal delegate void EqualizerStateChangedCallback(int equalizer, IntPtr userData);
71 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
72 internal delegate void RepeatModeChangedCallback(int repeat, IntPtr userData);
73 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
74 internal delegate void ShuffleModeChangedCallback(int shuffle, IntPtr userData);
75 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
76 internal delegate void ScanModeChangedCallback(int scan, IntPtr userData);
78 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
79 internal delegate void ConnectionChangedCallback(int result, bool connected, string deviceAddress, IntPtr userData);
80 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
81 internal delegate void ClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, string value, int len, IntPtr userData);
82 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
83 internal delegate void GattClientRequestedCallback(int result, IntPtr handle, IntPtr userData);
84 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
85 internal delegate bool GattForEachCallback(int total, int index, IntPtr handle, IntPtr userData);
87 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_initialize")]
88 internal static extern int Initialize();
89 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_deinitialize")]
90 internal static extern int Deinitialize();
92 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_name")]
93 internal static extern int GetName(out string name);
94 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_name")]
95 internal static extern int SetName(string name);
97 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_state")]
98 internal static extern int GetState(out BluetoothState isActivated);
99 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_address")]
100 internal static extern int GetAddress(out string address);
102 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_visibility")]
103 internal static extern int GetVisibility(out int visibility, out int duration);
105 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_is_discovering")]
106 internal static extern int IsDiscovering(out bool isDiscovering);
108 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_start_device_discovery")]
109 internal static extern int StartDiscovery();
110 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_stop_device_discovery")]
111 internal static extern int StopDiscovery();
113 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_foreach_bonded_device")]
114 internal static extern int GetBondedDevices(BondedDeviceCallback bondedDeviceCb, IntPtr userData);
116 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_bonded_device_info")]
117 internal static extern int GetBondedDeviceByAddress(string deviceAddress, out IntPtr deviceInfo);
118 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_free_device_info")]
119 internal static extern int FreeDeviceInfo(BluetoothDeviceStruct deviceInfo);
121 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_is_service_used")]
122 internal static extern int IsServiceUsed(string serviceUuid, out bool used);
124 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_local_oob_data")]
125 internal static extern int GetOobData(out IntPtr hash, out IntPtr randomizer, out int hashLen, out int randomizerLen);
126 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_remote_oob_data")]
127 internal static extern int SetOobData(string deviceAddress, IntPtr hash, IntPtr randomizer, int hashLen, int randomizerLen);
128 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_remove_remote_oob_data")]
129 internal static extern int RemoveOobData(string deviceAddress);
131 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_state_changed_cb")]
132 internal static extern int SetStateChangedCallback(StateChangedCallback stateChangedCb, IntPtr userData);
133 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_state_changed_cb")]
134 internal static extern int UnsetStateChangedCallback();
136 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_name_changed_cb")]
137 internal static extern int SetNameChangedCallback(NameChangedCallback nameChangedCb, IntPtr userData);
138 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_name_changed_cb")]
139 internal static extern int UnsetNameChangedCallback();
141 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_visibility_mode_changed_cb")]
142 internal static extern int SetVisibilityModeChangedCallback(VisibilityModeChangedCallback visibilityChangedCb, IntPtr userData);
143 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_visibility_mode_changed_cb")]
144 internal static extern int UnsetVisibilityModeChangedCallback();
146 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_visibility_duration_changed_cb")]
147 internal static extern int SetVisibilityDurationChangedCallback(VisibilityDurationChangedCallback durationChangedCb, IntPtr userData);
148 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_visibility_duration_changed_cb")]
149 internal static extern int UnsetVisibilityDurationChangedCallback();
151 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_device_discovery_state_changed_cb")]
152 internal static extern int SetDiscoveryStateChangedCallback(DiscoveryStateChangedCallback discoveryChangedCb, IntPtr userData);
153 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_device_discovery_state_changed_cb")]
154 internal static extern int UnsetDiscoveryStateChangedCallback();
157 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_create_bond")]
158 internal static extern int CreateBond(string deviceAddress);
159 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_destroy_bond")]
160 internal static extern int DestroyBond(string deviceAddress);
161 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_cancel_bonding")]
162 internal static extern int CancelBonding();
164 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_alias")]
165 internal static extern int SetAlias(string deviceAddress, string alias);
166 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_authorization")]
167 internal static extern int SetAuthorization(string deviceAddress, int state);
169 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_get_service_mask_from_uuid_list")]
170 internal static extern int GetMaskFromUuid([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 1)] string[] uuids, int count, out BluetoothServiceClassType serviceMask);
172 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_start_service_search")]
173 internal static extern int StartServiceSearch(string deviceAddress);
175 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_foreach_connected_profiles")]
176 internal static extern int GetConnectedProfiles(string deviceAddress, ConnectedProfileCallback connectedProfileCb, IntPtr userData);
177 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_is_profile_connected")]
178 internal static extern int IsProfileConnected(string deviceAddress, int profile, out bool connectionStatus);
180 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_bond_created_cb")]
181 internal static extern int SetBondCreatedCallback(BondCreatedCallback bondCreatedCb, IntPtr userData);
182 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_bond_created_cb")]
183 internal static extern int UnsetBondCreatedCallback();
185 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_bond_destroyed_cb")]
186 internal static extern int SetBondDestroyedCallback(BondDestroyedCallback bondDestroyedCb, IntPtr userData);
187 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_bond_destroyed_cb")]
188 internal static extern int UnsetBondDestroyedCallback();
190 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_authorization_changed_cb")]
191 internal static extern int SetAuthorizationChangedCallback(AuthorizationChangedCallback authorizationChangedCb, IntPtr userData);
192 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_authorization_changed_cb")]
193 internal static extern int UnsetAuthorizationChangedCallback();
195 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_service_searched_cb")]
196 internal static extern int SetServiceSearchedCallback(ServiceSearchedCallback serviceSearchedCb, IntPtr userData);
197 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_service_searched_cb")]
198 internal static extern int UnsetServiceSearchedCallback();
200 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_connection_state_changed_cb")]
201 internal static extern int SetConnectionStateChangedCallback(DeviceConnectionStateChangedCallback connectionChangedCb, IntPtr userData);
202 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_connection_state_changed_cb")]
203 internal static extern int UnsetConnectionStateChangedCallback();
205 // Bluetooth LE Adapter
208 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
209 internal delegate void AdapterLeScanResultChangedCallBack(int result,
210 [MarshalAs(UnmanagedType.Struct)]ref BluetoothLeScanDataStruct scanData, IntPtr userData);
212 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
213 public delegate void AdvertisingStateChangedCallBack(int result, IntPtr advertiserHandle,
214 BluetoothLeAdvertisingState advertisingState, IntPtr userData);
216 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
217 public delegate void GattConnectionStateChangedCallBack(int result, bool connected,
218 string remoteAddress, IntPtr userData);
220 //Bluetooth Le Adapter Apis
221 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_start_scan")]
222 public static extern int StartScan(AdapterLeScanResultChangedCallBack callback, IntPtr userData);
224 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_scan")]
225 public static extern int StopScan();
227 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_uuids")]
228 public static extern int GetScanResultServiceUuid(ref BluetoothLeScanDataStruct scanData,
229 BluetoothLePacketType packetType, ref IntPtr uuids, ref int count);
231 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_device_name")]
232 public static extern int GetLeScanResultDeviceName(ref BluetoothLeScanDataStruct scanData,
233 BluetoothLePacketType packetType, out string deviceName);
235 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_tx_power_level")]
236 public static extern int GetScanResultTxPowerLevel(ref BluetoothLeScanDataStruct scanData,
237 BluetoothLePacketType packetType, out int txPowerLevel);
239 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_solicitation_uuids")]
240 public static extern int GetScaResultSvcSolicitationUuids(ref BluetoothLeScanDataStruct scanData,
241 BluetoothLePacketType packetType, out IntPtr uuids, out int count);
243 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_data_list")]
244 public static extern int GetScanResultServiceDataList(ref BluetoothLeScanDataStruct scanData,
245 BluetoothLePacketType PacketType, out IntPtr serviceDataArray, out int count);
247 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_free_service_data_list")]
248 public static extern int FreeServiceDataList(IntPtr serviceData, int count);
250 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_appearance")]
\r
251 public static extern int GetScanResultAppearance(ref BluetoothLeScanDataStruct scanData,
252 BluetoothLePacketType packetType, out int appearance);
254 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_manufacturer_data")]
255 public static extern int GetScanResultManufacturerData(ref BluetoothLeScanDataStruct scanData,
256 BluetoothLePacketType packetType, out int manufId, out IntPtr manufData,
257 out int manufDataLength);
259 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_connect")]
260 internal static extern int GattConnect(string deviceAddress, bool autoConnect);
262 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_disconnect")]
263 internal static extern int GattDisconnect(string deviceAddress);
265 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_connection_state_changed_cb")]
266 internal static extern int SetGattConnectionStateChangedCallback(
267 GattConnectionStateChangedCallBack gattConnectionChangedCb, IntPtr userData);
269 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_unset_connection_state_changed_cb")]
270 internal static extern int UnsetGattConnectionStateChangedCallback();
272 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_create_advertiser")]
273 public static extern int CreateAdvertiser(out IntPtr advertiserHandle);
275 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_destroy_advertiser")]
276 public static extern int DestroyAdvertiser(IntPtr advertiserHandle);
278 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_uuid")]
279 public static extern int AddAdvertisingServiceUuid(IntPtr advertiserHandle,
280 BluetoothLePacketType PacketType, string uuid);
282 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_solicitation_uuid")]
283 public static extern int AddAdvertisingServiceSolicitationUuid(IntPtr advertiserHandle,
284 BluetoothLePacketType PacketType, string uuid);
286 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_data")]
287 public static extern int AddAdvertisingServiceData(IntPtr advertiserHandle,
288 BluetoothLePacketType PacketType, string uuid, IntPtr serviceData, int serviceDatalength);
290 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_appearance")]
291 public static extern int SetAdvertisingAppearance(IntPtr advertiserHandle,
292 BluetoothLePacketType packetType, int appearance);
294 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_manufacturer_data")]
295 public static extern int AddAdvertisingManufData(IntPtr advertiserHandle, BluetoothLePacketType packetType,
296 int manufId, IntPtr manufData, int manufacturerDataLength);
298 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_device_name")]
299 public static extern int SetAdvertisingDeviceName(IntPtr advertiserHandle, BluetoothLePacketType packetType,
302 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_tx_power_level")]
303 public static extern int SetAdvertisingTxPowerLevel(IntPtr advertiserHandle, BluetoothLePacketType packetType,
304 bool includePowerLevel);
306 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_clear_advertising_data")]
307 public static extern int ClearAdvertisingData(IntPtr advertiserHandle, BluetoothLePacketType packetType);
309 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_start_advertising_new")]
310 public static extern int BluetoothLeStartAdvertising(IntPtr advertiserHandle,
311 AdvertisingStateChangedCallBack callback, IntPtr userData);
313 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_advertising")]
314 public static extern int BluetoothLeStopAdvertising(IntPtr advertiserHandle);
316 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_mode")]
317 public static extern int SetAdvertisingMode(IntPtr advertiserHandle,
318 BluetoothLeAdvertisingMode advertisingMode);
320 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_connectable")]
321 public static extern int SetAdvertisingConnectable(IntPtr advertiserHandle,
325 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_create_rfcomm")]
326 internal static extern int CreateServerSocket(string serviceUuid, out int socketFd);
327 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_destroy_rfcomm")]
328 internal static extern int DestroyServerSocket(int socketFd);
329 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_listen_and_accept_rfcomm")]
330 internal static extern int Listen(int socketFd, int pendingConnections);
331 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_connect_rfcomm")]
332 internal static extern int ConnectSocket(string address, string serviceUuid);
333 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_disconnect_rfcomm")]
334 internal static extern int DisconnectSocket(int socketFd);
335 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_send_data")]
336 internal static extern int SendData(int socketFd, string data, int dataLength);
337 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_set_data_received_cb")]
338 internal static extern int SetDataReceivedCallback(DataReceivedCallback callback, IntPtr userData);
339 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_unset_data_received_cb")]
340 internal static extern int UnsetDataReceivedCallback();
341 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_set_connection_state_changed_cb")]
342 internal static extern int SetConnectionStateChangedCallback(SocketConnectionStateChangedCallback callback, IntPtr userData);
343 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_unset_connection_state_changed_cb")]
344 internal static extern int UnsetSocketConnectionStateChangedCallback();
347 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_initialize")]
348 internal static extern int InitializeAudio();
349 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_deinitialize")]
350 internal static extern int DeinitializeAudio();
352 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_connect")]
353 internal static extern int Connect(string deviceAddress, int profileType);
354 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_disconnect")]
355 internal static extern int Disconnect(string deviceAddress, int profileType);
357 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_set_connection_state_changed_cb")]
358 internal static extern int SetAudioConnectionStateChangedCallback(AudioConnectionStateChangedCallback audioStateChangedCb, IntPtr userData);
359 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_unset_connection_state_changed_cb")]
360 internal static extern int UnsetAudioConnectionStateChangedCallback();
363 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_initialize")]
364 internal static extern int InitializeHid(HidConnectionStateChangedCallback hidConnectionChangedCb, IntPtr userData);
365 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_deinitialize")]
366 internal static extern int DeinitializeHid();
368 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_connect")]
369 internal static extern int Connect(string deviceAddress);
370 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_disconnect")]
371 internal static extern int Disconnect(string deviceAddress);
374 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_initialize")]
375 internal static extern int InitializeAvrcp(TargetConnectionStateChangedCallback targetStateChangedCb, IntPtr userData);
376 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_deinitialize")]
377 internal static extern int DeinitializeAvrcp();
378 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_equalizer_state")]
379 internal static extern int NotifyEqualizerState(int state);
380 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_repeat_mode")]
381 internal static extern int NotifyRepeatMode(int repeat);
382 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_shuffle_mode")]
383 internal static extern int NotifyShuffleMode(int shuffle);
384 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_scan_mode")]
385 internal static extern int NotifyScanMode(int scan);
386 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_player_state")]
387 internal static extern int NotifyPlayerState(int state);
388 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_position")]
389 internal static extern int NotifyCurrentPosition(uint position);
390 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_track")]
391 internal static extern int NotifyTrack(string title, string artist, string album, string genre, uint trackNum, uint totaltracks, uint duration);
393 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_equalizer_state_changed_cb")]
394 internal static extern int SetEqualizerStateChangedCallback(EqualizerStateChangedCallback equalizerStateChangedCb, IntPtr userData);
395 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_equalizer_state_changed_cb")]
396 internal static extern int UnsetEqualizerStateChangedCallback();
397 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_repeat_mode_changed_cb")]
398 internal static extern int SetRepeatModeChangedCallback(RepeatModeChangedCallback repeatModeChangedCb, IntPtr userData);
399 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_repeat_mode_changed_cb")]
400 internal static extern int UnsetRepeatModeChangedCallback();
401 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_shuffle_mode_changed_cb")]
402 internal static extern int SetShuffleModeChangedCallback(ShuffleModeChangedCallback shuffleModeChangedCb, IntPtr userData);
403 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_shuffle_mode_changed_cb")]
404 internal static extern int UnsetShuffleModeChangedCallback();
405 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_scan_mode_changed_cb")]
406 internal static extern int SetScanModeChangedCallback(ScanModeChangedCallback scanModeChangedCb, IntPtr userData);
407 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_scan_mode_changed_cb")]
408 internal static extern int UnsetScanModeChangedCallback();
412 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
413 internal delegate bool BtGattForeachCallback(int total, int index, IntPtr gattHandle, IntPtr userData);
415 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
416 internal delegate void BtGattServerReadValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, int offset, IntPtr userData);
418 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
419 internal delegate void BtGattServerWriteValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, int offset, bool response_needed, byte[] value, int len, IntPtr userData);
421 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
422 internal delegate void BtClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, byte[] value, int len, IntPtr userData);
424 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
425 internal delegate void BtGattServerNotificationStateChangeCallback(bool notify, IntPtr serverHandle, IntPtr characteristicHandle, IntPtr userData);
427 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
428 internal delegate void BtGattServerNotificationSentCallback(int result, string clientAddress, IntPtr serverHandle, IntPtr characteristicHandle, bool completed, IntPtr userData);
430 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
431 internal delegate void BtGattClientRequestCompletedCallback(int result, IntPtr requestHandle, IntPtr userData);
435 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_destroy")]
436 internal static extern int BtGattDestroy(IntPtr gattHandle);
438 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_uuid")]
439 internal static extern int BtGattGetUuid(BluetoothGattAttributeHandle gattHandle, out string uuid);
441 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_value")]
442 internal static extern int BtGattGetValue(BluetoothGattAttributeHandle gattHandle, out IntPtr nativeValue, out int valueLength);
444 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_value")]
445 internal static extern int BtGattSetValue(BluetoothGattAttributeHandle gattHandle, byte[] value, int valueLength);
447 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_int_value")]
448 internal static extern int BtGattGetIntValue(BluetoothGattAttributeHandle gattHandle, int type, int offset, out int value);
450 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_int_value")]
451 internal static extern int BtGattSetIntValue(BluetoothGattAttributeHandle gattHandle, int type, int value, int offset);
453 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_float_value")]
454 internal static extern int BtGattGetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int offset, out float value);
456 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_float_value")]
457 internal static extern int BtGattSetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int mantissa, int exponent, int offset);
461 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_create")]
462 internal static extern int BtGattDescriptorCreate(string uuid, int permissions, byte[] value, int valueLength, out BluetoothGattAttributeHandle descriptorHandle);
464 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_get_permissions")]
465 internal static extern int BtGattDescriptorGetPermissions(BluetoothGattAttributeHandle descriptorHandle, out int permissions);
467 // GATT Characteristic
469 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_create")]
470 internal static extern int BtGattCharacteristicCreate(string uuid, int permissions, int properties, byte[] value, int valueLength, out BluetoothGattAttributeHandle characteristicHandle);
472 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_permissions")]
473 internal static extern int BtGattCharacteristicGetPermissions(BluetoothGattAttributeHandle characteristicHandle, out int permissions);
475 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_properties")]
476 internal static extern int BtGattCharacteristicGetProperties(BluetoothGattAttributeHandle characteristicHandle, out int properties);
478 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_set_properties")]
479 internal static extern int BtGattCharacteristicSetProperties(BluetoothGattAttributeHandle characteristicHandle, int properties);
481 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_write_type")]
482 internal static extern int BtGattCharacteristicGetWriteType(BluetoothGattAttributeHandle characteristicHandle, out int writeType);
484 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_set_write_type")]
485 internal static extern int BtGattCharacteristicSetWriteType(BluetoothGattAttributeHandle characteristicHandle, int writeType);
487 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_add_descriptor")]
488 internal static extern int BtGattCharacteristicAddDescriptor(BluetoothGattAttributeHandle characteristicHandle, BluetoothGattAttributeHandle descriptorHandle);
490 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_descriptor")]
491 internal static extern int BtGattCharacteristicGetDescriptor(BluetoothGattAttributeHandle characteristicHandle, string uuid, out BluetoothGattAttributeHandle descriptorHandle);
493 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_foreach_descriptors")]
494 internal static extern int BtGattCharacteristicForeachDescriptors(BluetoothGattAttributeHandle characteristicHandle, BtGattForeachCallback callback, IntPtr userData);
496 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_set_characteristic_value_changed_cb")]
497 internal static extern int BtGattClientSetCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle, BtClientCharacteristicValueChangedCallback cb, IntPtr userData);
499 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_unset_characteristic_value_changed_cb")]
500 internal static extern int BtGattClientUnsetCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle);
504 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_create")]
505 internal static extern int BtGattServiceCreate(string uuid, int type, out BluetoothGattAttributeHandle serviceHandle);
507 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_add_characteristic")]
508 internal static extern int BtGattServiceAddCharacteristic(BluetoothGattAttributeHandle serviceHandle, BluetoothGattAttributeHandle characteristicHandle);
510 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_get_characteristic")]
511 internal static extern int BtGattServiceGetCharacteristic(BluetoothGattAttributeHandle serviceHandle, string uuid, out BluetoothGattAttributeHandle characteristicHandle);
513 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_foreach_characteristics")]
514 internal static extern int BtGattServiceForeachCharacteristics(BluetoothGattAttributeHandle serviceHandle, BtGattForeachCallback callback, IntPtr userData);
516 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_add_included_service")]
517 internal static extern int BtGattServiceAddIncludedService(BluetoothGattAttributeHandle serviceHandle, BluetoothGattAttributeHandle includedServiceHandle);
519 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_get_included_service")]
520 internal static extern int BtGattServiceGetIncludedService(BluetoothGattAttributeHandle serviceHandle, string uuid, out BluetoothGattAttributeHandle includedServiceHandle);
522 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_foreach_included_services")]
523 internal static extern int BtGattServiceForeachIncludedServices(BluetoothGattAttributeHandle serviceHandle, BtGattForeachCallback callback, IntPtr userData);
527 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_destroy")]
528 internal static extern int BtGattClientDestroy(IntPtr clientHandle);
530 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_create")]
531 internal static extern int BtGattClientCreate(string remoteAddress, out BluetoothGattClientHandle clientHandle);
533 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_get_remote_address")]
534 internal static extern int BtGattClientGetRemoteAddress(BluetoothGattClientHandle clientHandle, out string remoteAddress);
536 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_get_service")]
537 internal static extern int BtGattClientGetService(BluetoothGattClientHandle clientHandle, string uuid, out BluetoothGattAttributeHandle serviceHandle);
539 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_foreach_services")]
540 internal static extern int BtGattClientForeachServices(BluetoothGattClientHandle clientHandle, BtGattForeachCallback callback, IntPtr userData);
542 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_read_value")]
543 internal static extern int BtGattClientReadValue(BluetoothGattAttributeHandle gattHandle, BtGattClientRequestCompletedCallback callback, IntPtr userData);
545 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_write_value")]
546 internal static extern int BtGattClientWriteValue(BluetoothGattAttributeHandle gattHandle, BtGattClientRequestCompletedCallback callback, IntPtr userData);
550 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_destroy")]
551 internal static extern int BtGattServerDestroy(IntPtr serverHandle);
553 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_create")]
554 internal static extern int BtGattServerCreate(out BluetoothGattServerHandle serverHandle);
556 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_initialize")]
557 internal static extern int BtGattServerInitialize();
559 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_deinitialize")]
560 internal static extern int BtGattServerDeinitialize();
562 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_read_value_requested_cb")]
563 internal static extern int BtGattServerSetReadValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerReadValueRequestedCallback callback, IntPtr userData);
565 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_write_value_requested_cb")]
566 internal static extern int BtGattServerSetWriteValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerWriteValueRequestedCallback callback, IntPtr userData);
568 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_characteristic_notification_state_change_cb")]
569 internal static extern int BtGattServeSetNotificationStateChangeCallback(BluetoothGattAttributeHandle characteristicHandle, BtGattServerNotificationStateChangeCallback callback, IntPtr userData);
571 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_start")]
572 internal static extern int BtGattServerStart();
574 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_register_service")]
575 internal static extern int BtGattServerRegisterService(BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle serviceHandle);
577 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unregister_service")]
578 internal static extern int BtGattServerUnregisterService(BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle serviceHandle);
580 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unregister_all_services")]
581 internal static extern int BtGattServerUnregisterAllServices(BluetoothGattServerHandle serverHandle);
583 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_get_service")]
584 internal static extern int BtGattServerGetService(BluetoothGattServerHandle serverHandle, string uuid, out BluetoothGattAttributeHandle serviceHandle);
586 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_foreach_services")]
587 internal static extern int BtGattServerForeachServices(BluetoothGattServerHandle serverHandle, BtGattForeachCallback callback, IntPtr userData);
589 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_send_response")]
590 internal static extern int BtGattServerSendResponse(int requestId, int requestType, int offset, int status, byte[] value, int valueLen);
592 [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_notify_characteristic_changed_value")]
593 internal static extern int BtGattServerNotify(BluetoothGattAttributeHandle characteristicHandle, BtGattServerNotificationSentCallback callback, string clientAddress, IntPtr userData);