1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NAPI_BLUETOOTH_CONNECTION_H 17 #define NAPI_BLUETOOTH_CONNECTION_H 18 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 #include "bluetooth_host.h" 22 23 namespace OHOS { 24 namespace Bluetooth { 25 enum class BondState { BOND_STATE_INVALID = 0, BOND_STATE_BONDING = 1, BOND_STATE_BONDED = 2 }; 26 27 enum class ScanMode { 28 SCAN_MODE_NONE = 0, 29 SCAN_MODE_CONNECTABLE = 1, 30 SCAN_MODE_GENERAL_DISCOVERABLE = 2, 31 SCAN_MODE_LIMITED_DISCOVERABLE = 3, 32 SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE = 4, 33 SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE = 5 34 }; 35 36 enum class BluetoothTransport { TRANSPORT_BR_EDR = 0, TRANSPORT_LE = 1 }; 37 38 const std::string REGISTER_DEVICE_FIND_TYPE = "bluetoothDeviceFind"; 39 const std::string REGISTER_PIN_REQUEST_TYPE = "pinRequired"; 40 const std::string REGISTER_BOND_STATE_TYPE = "bondStateChange"; 41 const std::string INVALID_PIN_CODE = "000000"; 42 43 napi_value DefineConnectionFunctions(napi_env env, napi_value exports); 44 napi_value GetBtConnectionState(napi_env env, napi_callback_info info); 45 #ifdef BLUETOOTH_API_SINCE_10 46 napi_value PairDeviceAsync(napi_env env, napi_callback_info info); 47 napi_value CancelPairedDeviceAsync(napi_env env, napi_callback_info info); 48 #else 49 napi_value PairDevice(napi_env env, napi_callback_info info); 50 napi_value CancelPairedDevice(napi_env env, napi_callback_info info); 51 #endif 52 napi_value GetRemoteDeviceName(napi_env env, napi_callback_info info); 53 napi_value GetRemoteDeviceClass(napi_env env, napi_callback_info info); 54 napi_value GetLocalName(napi_env env, napi_callback_info info); 55 napi_value GetPairedDevices(napi_env env, napi_callback_info info); 56 napi_value GetProfileConnectionState(napi_env env, napi_callback_info info); 57 napi_value SetDevicePairingConfirmation(napi_env env, napi_callback_info info); 58 napi_value SetLocalName(napi_env env, napi_callback_info info); 59 napi_value SetBluetoothScanMode(napi_env env, napi_callback_info info); 60 napi_value GetBluetoothScanMode(napi_env env, napi_callback_info info); 61 napi_value StartBluetoothDiscovery(napi_env env, napi_callback_info info); 62 napi_value StopBluetoothDiscovery(napi_env env, napi_callback_info info); 63 napi_value RegisterConnectionObserver(napi_env env, napi_callback_info info); 64 napi_value DeRegisterConnectionObserver(napi_env env, napi_callback_info info); 65 #ifdef BLUETOOTH_API_SINCE_10 66 napi_value SetDevicePinCode(napi_env env, napi_callback_info info); 67 napi_value CancelPairingDevice(napi_env env, napi_callback_info info); 68 napi_value PairCredibleDevice(napi_env env, napi_callback_info info); 69 napi_value GetLocalProfileUuids(napi_env env, napi_callback_info info); 70 napi_value GetRemoteProfileUuids(napi_env env, napi_callback_info info); 71 #endif 72 73 napi_value ConnectionPropertyValueInit(napi_env env, napi_value exports); 74 napi_value ScanModeInit(napi_env env); 75 napi_value BondStateInit(napi_env env); 76 #ifdef BLUETOOTH_API_SINCE_10 77 napi_value BluetoothTransportInit(napi_env env); 78 napi_value PinTypeInit(napi_env env); 79 #endif 80 81 void AddDiscoveryDevice(std::shared_ptr<BluetoothRemoteDevice> &device); 82 void RegisterObserverToHost(); 83 int GetDeviceTransport(const std::string &device); 84 } // namespace Bluetooth 85 } // namespace OHOS 86 87 #endif