• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 PBAP_PCE_CONNECTING_STATE_H
17 #define PBAP_PCE_CONNECTING_STATE_H
18 
19 #include <cstring>
20 #include "../obex/obex_client.h"
21 #include "../obex/obex_headers.h"
22 #include "base_observer_list.h"
23 #include "interface_profile_pbap_pce.h"
24 #include "message.h"
25 #include "pbap_pce_base_state.h"
26 #include "pbap_pce_header_msg.h"
27 #include "pbap_pce_state_machine.h"
28 
29 namespace OHOS {
30 namespace bluetooth {
31 /**
32  * @brief connecting statemachine
33  * control connecting state
34  */
35 class PceConnectingState : public PceBaseState {
36 public:
37     explicit PceConnectingState(
38         const std::string &name, PbapPceStateMachine &stm, BaseObserverList<IPbapPceObserver> &observerMgrList);
39 
40     /**
41      * @brief destructor
42      * @details destructor
43      */
44     ~PceConnectingState() override = default;
45 
46     /**
47      * @brief entry
48      * @details when become connecting, call this
49      * @return void
50      */
51     void Entry() override;
52 
53     /**
54      * @brief exit
55      * @details when leave connecting, call this
56      * @return void
57      */
58     void Exit() override;
59 
60     /**
61      * @brief Dispatch
62      * @details when Dispatch PceConnectingState, call this
63      * @param msg message
64      * @return bool true:success false:failure
65      */
66     bool Dispatch(const utility::Message &msg) override;
67 
68 private:
69     /**
70      * @brief connect to obex
71      * @details connect to obex
72      * @param sdpMsg pass obex message
73      * @return int @c  0 success
74      *              @c -1 failure
75      */
76     int ObexConnect(const PbapPceHeaderSdpMsg &sdpMsg);
77 
78     /**
79      * @brief reconnect to obex
80      * @details reconnect to obex
81      * @param sdpMsg pass obex message
82      * @return int @c  0 success
83      *              @c -1 failure
84      */
85     int ObexReconnect(const PbapPceObexMessage &obexMsg);
86 
87     /**
88      * @brief set Obex Client Config
89      * @details set Obex Client Config
90      * @param obexConfig Client Config
91      * @return
92      */
93     void SetObexClientConfigDetail(ObexClientConfig &obexConfig) const;
94 
95     /**
96      * @brief register gap
97      * @details register gap
98      * @param sdpMsg pass gap message
99      * @return
100      */
101     void RegGap(const PbapPceHeaderSdpMsg &sdpMsg) const;
102 
103     /**
104      * @brief input password
105      * @details input password
106      * @param pwdInputMsg input password
107      * @return
108      */
109     void PasswordInput(const PbapPcePasswordInputMsg &pwdInputMsg) const;
110 
111     /**
112      * @brief send request
113      * @details send request
114      * @return
115      */
116     void SendRequest() const;
117 
118     /**
119      * @brief InitAuth
120      * @details Initialize Auth data
121      */
122     void InitAuth();
123 
124     /**
125      * @brief SaveObexDigestChallenge
126      * @details Save ObexDigestChallenge
127      * @return int @c  0 success
128      *             @c -1 failure
129      */
130     int SaveObexDigestChallenge(const ObexDigestChallenge &digestChallenge);
131 
132     /**
133      * @brief Process ObexConnected
134      * @details Process ObexConnected
135      * @param msg
136      */
137     void ProcessObexConnected(const utility::Message &msg);
138 
139     /**
140      * @brief Process SdpFinish
141      * @details Process SdpFinish
142      * @param msg
143      */
144     void ProcessSdpFinish(const utility::Message &msg);
145 
146     /**
147      * @brief Process GapFinish
148      * @details Process GapFinish
149      * @param msg
150      */
151     void ProcessGapFinish(const utility::Message &msg) const;
152 
153     /**
154      * @brief Process ObexConnectFailed
155      * @details Process ObexConnectFailed
156      * @param msg
157      */
158     void ProcessObexConnectFailed(const utility::Message &msg);
159 
160     /**
161      * @brief Process ObexTransportFailed
162      * @details Process ObexTransportFailed
163      * @param msg
164      */
165     void ProcessObexTransportFailed(const utility::Message &msg);
166 
167     /**
168      * @brief Process PasswordInput
169      * @details Process PasswordInput
170      * @param msg
171      */
172     void ProcessPasswordInput(const utility::Message &msg) const;
173 
174     ObexClientConfig obexConfig_ {};
175     std::vector<uint8_t> authDescription_ {};
176     std::vector<uint8_t> authNonce_ {};
177     uint8_t authUserCharset_ = 0;
178     bool authFullAccess_ = false;
179     bool authNeedUser_ = false;
180     bool authChallenge_ = false;
181     std::unique_ptr<ObexHeader> header_ {nullptr};
182 };
183 }  // namespace bluetooth
184 }  // namespace OHOS
185 
186 #endif  // PBAP_PCE_CONNECTING_STATE_H
187