michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__ michael@0: #define mozilla_dom_bluetooth_bluetoothhfpmanager_h__ michael@0: michael@0: #include "BluetoothCommon.h" michael@0: #include "BluetoothHfpManagerBase.h" michael@0: #ifdef MOZ_B2G_RIL michael@0: #include "BluetoothRilListener.h" michael@0: #endif michael@0: #include "BluetoothSocketObserver.h" michael@0: #include "mozilla/ipc/UnixSocket.h" michael@0: #include "mozilla/Hal.h" michael@0: michael@0: BEGIN_BLUETOOTH_NAMESPACE michael@0: michael@0: class BluetoothReplyRunnable; michael@0: class BluetoothSocket; michael@0: michael@0: #ifdef MOZ_B2G_RIL michael@0: class Call; michael@0: michael@0: /** michael@0: * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07 michael@0: * and 3GPP 27.007" in Bluetooth hands-free profile 1.6 michael@0: */ michael@0: enum BluetoothCmeError { michael@0: AG_FAILURE = 0, michael@0: NO_CONNECTION_TO_PHONE = 1, michael@0: OPERATION_NOT_ALLOWED = 3, michael@0: OPERATION_NOT_SUPPORTED = 4, michael@0: PIN_REQUIRED = 5, michael@0: SIM_NOT_INSERTED = 10, michael@0: SIM_PIN_REQUIRED = 11, michael@0: SIM_PUK_REQUIRED = 12, michael@0: SIM_FAILURE = 13, michael@0: SIM_BUSY = 14, michael@0: INCORRECT_PASSWORD = 16, michael@0: SIM_PIN2_REQUIRED = 17, michael@0: SIM_PUK2_REQUIRED = 18, michael@0: MEMORY_FULL = 20, michael@0: INVALID_INDEX = 21, michael@0: MEMORY_FAILURE = 23, michael@0: TEXT_STRING_TOO_LONG = 24, michael@0: INVALID_CHARACTERS_IN_TEXT_STRING = 25, michael@0: DIAL_STRING_TOO_LONG = 26, michael@0: INVALID_CHARACTERS_IN_DIAL_STRING = 27, michael@0: NO_NETWORK_SERVICE = 30, michael@0: NETWORK_TIMEOUT = 31, michael@0: NETWORK_NOT_ALLOWED = 32 michael@0: }; michael@0: michael@0: enum PhoneType { michael@0: NONE, // no connection michael@0: GSM, michael@0: CDMA michael@0: }; michael@0: michael@0: class Call { michael@0: public: michael@0: Call(); michael@0: void Reset(); michael@0: bool IsActive(); michael@0: michael@0: uint16_t mState; michael@0: bool mDirection; // true: incoming call; false: outgoing call michael@0: bool mIsConference; michael@0: nsString mNumber; michael@0: int mType; michael@0: }; michael@0: #endif // MOZ_B2G_RIL michael@0: michael@0: class BluetoothHfpManager : public BluetoothSocketObserver michael@0: , public BluetoothHfpManagerBase michael@0: , public BatteryObserver michael@0: { michael@0: public: michael@0: BT_DECL_HFP_MGR_BASE michael@0: virtual void GetName(nsACString& aName) michael@0: { michael@0: aName.AssignLiteral("HFP/HSP"); michael@0: } michael@0: michael@0: static BluetoothHfpManager* Get(); michael@0: ~BluetoothHfpManager(); michael@0: michael@0: // The following functions are inherited from BluetoothSocketObserver michael@0: virtual void ReceiveSocketData( michael@0: BluetoothSocket* aSocket, michael@0: nsAutoPtr& aMessage) MOZ_OVERRIDE; michael@0: virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE; michael@0: virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE; michael@0: virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE; michael@0: michael@0: bool Listen(); michael@0: /** michael@0: * This function set up a Synchronous Connection (SCO) link for HFP. michael@0: * Service Level Connection (SLC) should be established before SCO setup michael@0: * process. michael@0: * If SLC haven't been established, this function will return false and michael@0: * send a request to set up SCO ater HfpManager receive AT+CMER, unless we are michael@0: * connecting HSP socket rather than HFP socket. michael@0: * michael@0: * @param aRunnable Indicate a BluetoothReplyRunnable to execute this michael@0: * function. The default value is nullpter michael@0: * @return true if SCO established successfully michael@0: */ michael@0: bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr); michael@0: bool DisconnectSco(); michael@0: bool ListenSco(); michael@0: michael@0: #ifdef MOZ_B2G_RIL michael@0: /** michael@0: * @param aSend A boolean indicates whether we need to notify headset or not michael@0: */ michael@0: void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState, michael@0: const nsAString& aError, const nsAString& aNumber, michael@0: const bool aIsOutgoing, const bool aIsConference, michael@0: bool aSend); michael@0: void HandleIccInfoChanged(uint32_t aClientId); michael@0: void HandleVoiceConnectionChanged(uint32_t aClientId); michael@0: michael@0: // CDMA-specific functions michael@0: void UpdateSecondNumber(const nsAString& aNumber); michael@0: void AnswerWaitingCall(); michael@0: void IgnoreWaitingCall(); michael@0: void ToggleCalls(); michael@0: #endif michael@0: michael@0: private: michael@0: class CloseScoTask; michael@0: class GetVolumeTask; michael@0: #ifdef MOZ_B2G_RIL michael@0: class RespondToBLDNTask; michael@0: class SendRingIndicatorTask; michael@0: #endif michael@0: michael@0: friend class CloseScoTask; michael@0: friend class GetVolumeTask; michael@0: #ifdef MOZ_B2G_RIL michael@0: friend class RespondToBLDNTask; michael@0: friend class SendRingIndicatorTask; michael@0: #endif michael@0: friend class BluetoothHfpManagerObserver; michael@0: michael@0: BluetoothHfpManager(); michael@0: void HandleShutdown(); michael@0: void HandleVolumeChanged(const nsAString& aData); michael@0: michael@0: bool Init(); michael@0: void Notify(const hal::BatteryInformation& aBatteryInfo); michael@0: #ifdef MOZ_B2G_RIL michael@0: void ResetCallArray(); michael@0: uint32_t FindFirstCall(uint16_t aState); michael@0: uint32_t GetNumberOfCalls(uint16_t aState); michael@0: uint32_t GetNumberOfConCalls(); michael@0: uint32_t GetNumberOfConCalls(uint16_t aState); michael@0: PhoneType GetPhoneType(const nsAString& aType); michael@0: #endif michael@0: michael@0: void NotifyConnectionStatusChanged(const nsAString& aType); michael@0: void NotifyDialer(const nsAString& aCommand); michael@0: michael@0: #ifdef MOZ_B2G_RIL michael@0: void SendCCWA(const nsAString& aNumber, int aType); michael@0: bool SendCLCC(const Call& aCall, int aIndex); michael@0: #endif michael@0: bool SendCommand(const char* aCommand, uint32_t aValue = 0); michael@0: bool SendLine(const char* aMessage); michael@0: #ifdef MOZ_B2G_RIL michael@0: void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend = true); michael@0: #endif michael@0: void OnScoConnectSuccess(); michael@0: void OnScoConnectError(); michael@0: void OnScoDisconnect(); michael@0: michael@0: int mCurrentVgs; michael@0: int mCurrentVgm; michael@0: #ifdef MOZ_B2G_RIL michael@0: bool mBSIR; michael@0: bool mCCWA; michael@0: bool mCLIP; michael@0: #endif michael@0: bool mCMEE; michael@0: bool mCMER; michael@0: bool mConnectScoRequest; michael@0: bool mSlcConnected; michael@0: bool mIsHsp; michael@0: #ifdef MOZ_B2G_RIL michael@0: bool mFirstCKPD; michael@0: int mNetworkSelectionMode; michael@0: PhoneType mPhoneType; michael@0: #endif michael@0: bool mReceiveVgsFlag; michael@0: #ifdef MOZ_B2G_RIL michael@0: bool mDialingRequestProcessed; michael@0: #endif michael@0: nsString mDeviceAddress; michael@0: #ifdef MOZ_B2G_RIL michael@0: nsString mMsisdn; michael@0: nsString mOperatorName; michael@0: michael@0: nsTArray mCurrentCallArray; michael@0: nsAutoPtr mListener; michael@0: #endif michael@0: nsRefPtr mController; michael@0: nsRefPtr mScoRunnable; michael@0: michael@0: // If a connection has been established, mSocket will be the socket michael@0: // communicating with the remote socket. We maintain the invariant that if michael@0: // mSocket is non-null, mHandsfreeSocket and mHeadsetSocket must be null (and michael@0: // vice versa). michael@0: nsRefPtr mSocket; michael@0: michael@0: // Server sockets. Once an inbound connection is established, it will hand michael@0: // over the ownership to mSocket, and get a new server socket while Listen() michael@0: // is called. michael@0: nsRefPtr mHandsfreeSocket; michael@0: nsRefPtr mHeadsetSocket; michael@0: nsRefPtr mScoSocket; michael@0: mozilla::ipc::SocketConnectionStatus mScoSocketStatus; michael@0: michael@0: #ifdef MOZ_B2G_RIL michael@0: // CDMA-specific variable michael@0: Call mCdmaSecondCall; michael@0: #endif michael@0: }; michael@0: michael@0: END_BLUETOOTH_NAMESPACE michael@0: michael@0: #endif