2014-06-27 00:45:26 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothinterface_h__
|
|
|
|
#define mozilla_dom_bluetooth_bluedroid_bluetoothinterface_h__
|
|
|
|
|
|
|
|
#include <hardware/bluetooth.h>
|
|
|
|
#include <hardware/bt_sock.h>
|
|
|
|
#include <hardware/bt_hf.h>
|
|
|
|
#include <hardware/bt_av.h>
|
|
|
|
#if ANDROID_VERSION >= 18
|
|
|
|
#include <hardware/bt_rc.h>
|
|
|
|
#endif
|
|
|
|
#include "BluetoothCommon.h"
|
|
|
|
|
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
class BluetoothInterface;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Socket Interface
|
|
|
|
//
|
|
|
|
|
|
|
|
class BluetoothSocketInterface
|
|
|
|
{
|
|
|
|
public:
|
2014-07-02 19:58:00 -07:00
|
|
|
friend class BluetoothInterface;
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
// Init and Cleanup is handled by BluetoothInterface
|
|
|
|
|
|
|
|
bt_status_t Listen(btsock_type_t aType,
|
|
|
|
const char* aServiceName, const uint8_t* aServiceUuid,
|
|
|
|
int aChannel, int& aSockFd, int aFlags);
|
|
|
|
|
|
|
|
bt_status_t Connect(const bt_bdaddr_t* aBdAddr, btsock_type_t aType,
|
|
|
|
const uint8_t* aUuid, int aChannel, int& aSockFd,
|
|
|
|
int aFlags);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BluetoothSocketInterface(const btsock_interface_t* aInterface);
|
|
|
|
~BluetoothSocketInterface();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const btsock_interface_t* mInterface;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Handsfree Interface
|
|
|
|
//
|
|
|
|
|
|
|
|
class BluetoothHandsfreeInterface
|
|
|
|
{
|
|
|
|
public:
|
2014-07-02 19:58:00 -07:00
|
|
|
friend class BluetoothInterface;
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
bt_status_t Init(bthf_callbacks_t* aCallbacks);
|
|
|
|
void Cleanup();
|
|
|
|
|
|
|
|
/* Connect / Disconnect */
|
|
|
|
|
|
|
|
bt_status_t Connect(bt_bdaddr_t* aBdAddr);
|
|
|
|
bt_status_t Disconnect(bt_bdaddr_t* aBdAddr);
|
|
|
|
bt_status_t ConnectAudio(bt_bdaddr_t* aBdAddr);
|
|
|
|
bt_status_t DisconnectAudio(bt_bdaddr_t* aBdAddr);
|
|
|
|
|
|
|
|
/* Voice Recognition */
|
|
|
|
|
|
|
|
bt_status_t StartVoiceRecognition();
|
|
|
|
bt_status_t StopVoiceRecognition();
|
|
|
|
|
|
|
|
/* Volume */
|
|
|
|
|
|
|
|
bt_status_t VolumeControl(bthf_volume_type_t aType, int aVolume);
|
|
|
|
|
|
|
|
/* Device status */
|
|
|
|
|
|
|
|
bt_status_t DeviceStatusNotification(bthf_network_state_t aNtkState,
|
|
|
|
bthf_service_type_t aSvcType,
|
|
|
|
int aSignal, int aBattChg);
|
|
|
|
|
|
|
|
/* Responses */
|
|
|
|
|
|
|
|
bt_status_t CopsResponse(const char* aCops);
|
|
|
|
bt_status_t CindResponse(int aSvc, int aNumActive, int aNumHeld,
|
|
|
|
bthf_call_state_t aCallSetupState, int aSignal,
|
|
|
|
int aRoam, int aBattChg);
|
|
|
|
bt_status_t FormattedAtResponse(const char* aRsp);
|
|
|
|
bt_status_t AtResponse(bthf_at_response_t aResponseCode, int aErrorCode);
|
|
|
|
bt_status_t ClccResponse(int aIndex, bthf_call_direction_t aDir,
|
|
|
|
bthf_call_state_t aState, bthf_call_mode_t aMode,
|
|
|
|
bthf_call_mpty_type_t aMpty, const char* aNumber,
|
|
|
|
bthf_call_addrtype_t aType);
|
|
|
|
|
|
|
|
/* Phone State */
|
|
|
|
|
|
|
|
bt_status_t PhoneStateChange(int aNumActive, int aNumHeld,
|
|
|
|
bthf_call_state_t aCallSetupState,
|
|
|
|
const char* aNumber,
|
|
|
|
bthf_call_addrtype_t aType);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BluetoothHandsfreeInterface(const bthf_interface_t* aInterface);
|
|
|
|
~BluetoothHandsfreeInterface();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const bthf_interface_t* mInterface;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Bluetooth Advanced Audio Interface
|
|
|
|
//
|
|
|
|
|
|
|
|
class BluetoothA2dpInterface
|
|
|
|
{
|
|
|
|
public:
|
2014-07-02 19:58:00 -07:00
|
|
|
friend class BluetoothInterface;
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
bt_status_t Init(btav_callbacks_t *aCallbacks);
|
|
|
|
void Cleanup();
|
|
|
|
|
|
|
|
bt_status_t Connect(bt_bdaddr_t *aBdAddr);
|
|
|
|
bt_status_t Disconnect(bt_bdaddr_t *aBdAddr);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BluetoothA2dpInterface(const btav_interface_t* aInterface);
|
|
|
|
~BluetoothA2dpInterface();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const btav_interface_t* mInterface;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Bluetooth AVRCP Interface
|
|
|
|
//
|
|
|
|
|
|
|
|
class BluetoothAvrcpInterface
|
|
|
|
{
|
|
|
|
#if ANDROID_VERSION >= 18
|
|
|
|
public:
|
2014-07-02 19:58:00 -07:00
|
|
|
friend class BluetoothInterface;
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
bt_status_t Init(btrc_callbacks_t* aCallbacks);
|
|
|
|
void Cleanup();
|
|
|
|
|
|
|
|
bt_status_t GetPlayStatusRsp(btrc_play_status_t aPlayStatus,
|
|
|
|
uint32_t aSongLen, uint32_t aSongPos);
|
|
|
|
|
|
|
|
bt_status_t ListPlayerAppAttrRsp(int aNumAttr, btrc_player_attr_t* aPAttrs);
|
|
|
|
bt_status_t ListPlayerAppValueRsp(int aNumVal, uint8_t* aPVals);
|
|
|
|
|
|
|
|
bt_status_t GetPlayerAppValueRsp(btrc_player_settings_t* aPVals);
|
|
|
|
bt_status_t GetPlayerAppAttrTextRsp(int aNumAttr,
|
|
|
|
btrc_player_setting_text_t* aPAttrs);
|
|
|
|
bt_status_t GetPlayerAppValueTextRsp(int aNumVal,
|
|
|
|
btrc_player_setting_text_t* aPVals);
|
|
|
|
|
|
|
|
bt_status_t GetElementAttrRsp(uint8_t aNumAttr,
|
|
|
|
btrc_element_attr_val_t* aPAttrs);
|
|
|
|
|
|
|
|
bt_status_t SetPlayerAppValueRsp(btrc_status_t aRspStatus);
|
|
|
|
|
|
|
|
bt_status_t RegisterNotificationRsp(btrc_event_id_t aEventId,
|
|
|
|
btrc_notification_type_t aType,
|
|
|
|
btrc_register_notification_t* aPParam);
|
|
|
|
|
|
|
|
bt_status_t SetVolume(uint8_t aVolume);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BluetoothAvrcpInterface(const btrc_interface_t* aInterface);
|
|
|
|
~BluetoothAvrcpInterface();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const btrc_interface_t* mInterface;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Bluetooth Core Interface
|
|
|
|
//
|
|
|
|
|
2014-07-03 00:51:27 -07:00
|
|
|
class BluetoothResultHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothResultHandler)
|
|
|
|
|
|
|
|
virtual ~BluetoothResultHandler() { }
|
|
|
|
|
|
|
|
virtual void OnError(int aStatus)
|
|
|
|
{
|
|
|
|
BT_LOGR("received error code %d", aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Init() { }
|
|
|
|
virtual void Cleanup() { }
|
|
|
|
virtual void Enable() { }
|
|
|
|
virtual void Disable() { }
|
|
|
|
|
|
|
|
virtual void GetAdapterProperties() { }
|
|
|
|
virtual void GetAdapterProperty() { }
|
|
|
|
virtual void SetAdapterProperty() { }
|
|
|
|
|
|
|
|
virtual void GetRemoteDeviceProperties() { }
|
|
|
|
virtual void GetRemoteDeviceProperty() { }
|
|
|
|
virtual void SetRemoteDeviceProperty() { }
|
|
|
|
|
|
|
|
virtual void GetRemoteServiceRecord() { }
|
|
|
|
virtual void GetRemoteServices() { }
|
|
|
|
|
|
|
|
virtual void StartDiscovery() { }
|
|
|
|
virtual void CancelDiscovery() { }
|
|
|
|
|
|
|
|
virtual void CreateBond() { }
|
|
|
|
virtual void RemoveBond() { }
|
|
|
|
virtual void CancelBond() { }
|
|
|
|
|
|
|
|
virtual void PinReply() { }
|
|
|
|
virtual void SspReply() { }
|
|
|
|
|
|
|
|
virtual void DutModeConfigure() { }
|
|
|
|
virtual void DutModeSend() { }
|
|
|
|
|
|
|
|
virtual void LeTestMode() { }
|
|
|
|
};
|
|
|
|
|
2014-06-27 00:45:26 -07:00
|
|
|
class BluetoothInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static BluetoothInterface* GetInstance();
|
|
|
|
|
2014-07-03 00:51:57 -07:00
|
|
|
void Init(bt_callbacks_t* aCallbacks, BluetoothResultHandler* aRes);
|
|
|
|
void Cleanup(BluetoothResultHandler* aRes);
|
|
|
|
|
|
|
|
void Enable(BluetoothResultHandler* aRes);
|
|
|
|
void Disable(BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
/* Adapter Properties */
|
|
|
|
|
2014-07-03 00:52:19 -07:00
|
|
|
void GetAdapterProperties(BluetoothResultHandler* aRes);
|
|
|
|
void GetAdapterProperty(bt_property_type_t aType,
|
|
|
|
BluetoothResultHandler* aRes);
|
|
|
|
void SetAdapterProperty(const bt_property_t* aProperty,
|
|
|
|
BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* Remote Device Properties */
|
|
|
|
|
2014-07-03 00:52:35 -07:00
|
|
|
void GetRemoteDeviceProperties(bt_bdaddr_t *aRemoteAddr,
|
|
|
|
BluetoothResultHandler* aRes);
|
|
|
|
void GetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
|
|
|
bt_property_type_t aType,
|
|
|
|
BluetoothResultHandler* aRes);
|
|
|
|
void SetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
|
|
|
const bt_property_t* aProperty,
|
|
|
|
BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* Remote Services */
|
|
|
|
|
2014-07-03 00:52:52 -07:00
|
|
|
void GetRemoteServiceRecord(bt_bdaddr_t* aRemoteAddr,
|
|
|
|
bt_uuid_t* aUuid,
|
|
|
|
BluetoothResultHandler* aRes);
|
|
|
|
void GetRemoteServices(bt_bdaddr_t* aRemoteAddr,
|
|
|
|
BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* Discovery */
|
|
|
|
|
2014-07-03 00:53:06 -07:00
|
|
|
void StartDiscovery(BluetoothResultHandler* aRes);
|
|
|
|
void CancelDiscovery(BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* Bonds */
|
|
|
|
|
2014-07-03 00:53:20 -07:00
|
|
|
void CreateBond(const bt_bdaddr_t* aBdAddr, BluetoothResultHandler* aRes);
|
|
|
|
void RemoveBond(const bt_bdaddr_t* aBdAddr, BluetoothResultHandler* aRes);
|
|
|
|
void CancelBond(const bt_bdaddr_t* aBdAddr, BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* Authentication */
|
|
|
|
|
2014-07-03 00:53:32 -07:00
|
|
|
void PinReply(const bt_bdaddr_t* aBdAddr, uint8_t aAccept,
|
|
|
|
uint8_t aPinLen, bt_pin_code_t* aPinCode,
|
|
|
|
BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
2014-07-03 00:53:32 -07:00
|
|
|
void SspReply(const bt_bdaddr_t* aBdAddr, bt_ssp_variant_t aVariant,
|
|
|
|
uint8_t aAccept, uint32_t aPasskey,
|
|
|
|
BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* DUT Mode */
|
|
|
|
|
2014-07-03 00:53:39 -07:00
|
|
|
void DutModeConfigure(uint8_t aEnable, BluetoothResultHandler* aRes);
|
|
|
|
void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
|
|
|
BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* LE Mode */
|
|
|
|
|
2014-07-03 00:53:39 -07:00
|
|
|
void LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
|
|
|
BluetoothResultHandler* aRes);
|
2014-06-27 00:45:26 -07:00
|
|
|
|
|
|
|
/* Profile Interfaces */
|
|
|
|
|
|
|
|
BluetoothSocketInterface* GetBluetoothSocketInterface();
|
|
|
|
BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface();
|
|
|
|
BluetoothA2dpInterface* GetBluetoothA2dpInterface();
|
|
|
|
BluetoothAvrcpInterface* GetBluetoothAvrcpInterface();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BluetoothInterface(const bt_interface_t* aInterface);
|
|
|
|
~BluetoothInterface();
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <class T>
|
|
|
|
T* GetProfileInterface();
|
|
|
|
|
|
|
|
const bt_interface_t* mInterface;
|
|
|
|
};
|
|
|
|
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|