1 /* 2 * Copyright (C) 2021-2022 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 OHOS_P2P_IDLE_STATE_H 17 #define OHOS_P2P_IDLE_STATE_H 18 19 #include "state.h" 20 #include "p2p_define.h" 21 #include "wifi_p2p_group_manager.h" 22 #include "wifi_p2p_device_manager.h" 23 24 namespace OHOS { 25 namespace Wifi { 26 #define RETRY_TIMEOUT 10 27 #define RETRY_MAX_NUM 9 28 #define RETRY_INTERVAL 500 29 #define P2P_REMOVE_DEVICE_TIMEOUT 300000 30 class P2pStateMachine; 31 class P2pIdleState : public State { 32 FRIEND_GTEST(P2pIdleState); 33 34 public: 35 /** 36 * @Description Construct a new P2pIdleState object 37 * @param None 38 * @return None 39 */ 40 P2pIdleState(P2pStateMachine &stateMachine, WifiP2pGroupManager &groupMgr, WifiP2pDeviceManager &deviceMgr); 41 42 /** 43 * @Description Destroy the P2pIdleState object 44 * @param None 45 * @return None 46 */ 47 ~P2pIdleState() = default; 48 49 /** 50 * @Description - Called when entering state 51 * @param None 52 * @return None 53 */ 54 virtual void GoInState() override; 55 56 /** 57 * @Description - Called when exiting state 58 * @param None 59 * @return None 60 */ 61 virtual void GoOutState() override; 62 63 /** 64 * @Description - Message Processing Function 65 * @param msg - Message object pointer 66 * @return - bool true:success false:fail 67 */ 68 virtual bool ExecuteStateMsg(InternalMessagePtr msg) override; 69 70 private: 71 /** 72 * @Description Initialization 73 * @param None 74 * @return None 75 */ 76 virtual void Init(); 77 78 /** 79 * @Description Process the stop discover peer command received by the state machine 80 * @param msg - Message body sent by the state machine 81 * @return - bool true:handle false:not handle 82 */ 83 virtual bool ProcessCmdStopDiscPeer(InternalMessagePtr msg) const; 84 85 /** 86 * @Description Process the connect command received by the state machine 87 * @param msg - Message body sent by the state machine 88 * @return - bool true:handle false:not handle 89 */ 90 virtual bool ProcessCmdConnect(InternalMessagePtr msg) const; 91 92 /** 93 * @Description Process the provision discover pbc request message received by the state machine 94 * @param msg - Message body sent by the state machine 95 * @return - bool true:handle false:not handle 96 */ 97 virtual bool ProcessProvDiscPbcReqEvt(InternalMessagePtr msg) const; 98 99 /** 100 * @Description Process the provision discover enter pin message received by the state machine 101 * @param msg - Message body sent by the state machine 102 * @return - bool true:handle false:not handle 103 */ 104 virtual bool ProcessProvDiscEnterPinEvt(InternalMessagePtr msg) const; 105 106 /** 107 * @Description Process the negotiation request message received by the state machine 108 * @param msg - Message body sent by the state machine 109 * @return - bool true:handle false:not handle 110 */ 111 virtual bool ProcessNegotReqEvt(InternalMessagePtr msg) const; 112 113 /** 114 * @Description Process the provision discover show pin message received by the state machine 115 * @param msg - Message body sent by the state machine 116 * @return - bool true:handle false:not handle 117 */ 118 virtual bool ProcessProvDiscShowPinEvt(InternalMessagePtr msg) const; 119 120 /** 121 * @Description Process the create group command received by the state machine 122 * @param msg - Message body sent by the state machine 123 * @return - bool true:handle false:not handle 124 */ 125 virtual bool ProcessCmdCreateGroup(InternalMessagePtr msg) const; 126 127 /** 128 * @Description Process the remove group command received by the state machine 129 * @param msg - Message body sent by the state machine 130 * @return - bool true:handle false:not handle 131 */ 132 virtual bool ProcessCmdRemoveGroup(InternalMessagePtr msg) const; 133 134 /** 135 * @Description Process the delete group command received by the state machine 136 * @param msg - Message body sent by the state machine 137 * @return - bool true:handle false:not handle 138 */ 139 virtual bool ProcessCmdDeleteGroup(InternalMessagePtr msg) const; 140 141 /** 142 * @Description Process the group started message received by the state machine 143 * @param msg - Message body sent by the state machine 144 * @return - bool true:handle false:not handle 145 */ 146 virtual bool ProcessGroupStartedEvt(InternalMessagePtr msg) const; 147 148 /** 149 * @Description Process the invitation received message received by the state machine 150 * @param msg - Message body sent by the state machine 151 * @return - bool true:handle false:not handle 152 */ 153 virtual bool ProcessInvitationReceivedEvt(InternalMessagePtr msg) const; 154 155 /** 156 * @Description Process the hid2d create group command received by the state machine 157 * @param msg - Message body sent by the state machine 158 * @return - bool true:handle false:not handle 159 */ 160 virtual bool ProcessCmdHid2dCreateGroup(InternalMessagePtr msg) const; 161 162 /** 163 * @Description Process the hid2d connect command received by the state machine 164 * @param msg - Message body sent by the state machine 165 * @return - bool true:handle false:not handle 166 */ 167 virtual bool ProcessCmdHid2dConnect(InternalMessagePtr msg) const; 168 169 /** 170 * @Description Process p2p interface created event received by the state machine 171 * @param msg - Message body sent by the state machine 172 * @param @return - bool true:handle false:not handle 173 */ 174 virtual bool ProcessP2pIfaceCreatedEvt(InternalMessagePtr msg) const; 175 176 virtual bool ProcessRemoveDevice(InternalMessagePtr msg) const; 177 178 virtual bool RetryConnect(InternalMessagePtr msg) const; 179 180 virtual bool ProcessCmdDisableRandomMac(InternalMessagePtr msg) const; 181 private: 182 using ProcessFun = bool (P2pIdleState::*)(InternalMessagePtr msg) const; 183 std::map<P2P_STATE_MACHINE_CMD, ProcessFun> mProcessFunMap; 184 P2pStateMachine &p2pStateMachine; 185 WifiP2pGroupManager &groupManager; 186 WifiP2pDeviceManager &deviceManager; 187 static int retryConnectCnt; 188 static bool hasConnect; 189 }; 190 } // namespace Wifi 191 } // namespace OHOS 192 193 #endif /* OHOS_P2P_IDLE_STATE_H */ 194