wifi框架层流程之--EnableP2p流程
EnableP2p流程关键代码逻辑:

所在文件:foundation\communication\wifi\wifi\frameworks\native\src\wifi_p2p_impl.cpp
ErrCode WifiP2pImpl::EnableP2p(void) {
return client_->EnableP2p();
}
所在文件:foundation\communication\wifi\wifi\frameworks\native\src\wifi_p2p_proxy.cpp
ErrCode WifiP2pProxy::EnableP2p(void)
{
MessageOption option;
MessageParcel data, reply;
data.WriteInterfaceToken(GetDescriptor());
data.WriteInt32(0);
int error = Remote()->SendRequest(static_cast<uint32_t>(P2PInterfaceCode::WIFI_SVR_CMD_P2P_ENABLE), data, reply,
option);
int exception = reply.ReadInt32();
if (exception) {
return WIFI_OPT_FAILED;
}
return ErrCode(reply.ReadInt32());
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_p2p_sa\wifi_p2p_stub.cpp
handleFuncMap[static_cast<uint32_t>(P2PInterfaceCode::WIFI_SVR_CMD_P2P_ENABLE)] = [this](uint32_t code,
MessageParcel &data, MessageParcel &reply, MessageOption &option) { OnEnableP2p(code, data, reply, option); };
int WifiP2pStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
if (data.ReadInterfaceToken() != GetDescriptor()) {
return WIFI_OPT_FAILED;
}
HandleFuncMap::iterator iter = handleFuncMap.find(code);
(iter->second)(code, data, reply, option);
return 0;
}
void WifiP2pStub::OnEnableP2p(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
ErrCode ret = EnableP2p();
reply.WriteInt32(0);
reply.WriteInt32(ret);
return;
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_p2p_sa\wifi_p2p_service_impl.cpp
ErrCode WifiP2pServiceImpl::EnableP2p(void)
{
ErrCode errCode = CheckCanEnableP2p();
if (errCode != WIFI_OPT_SUCCESS) {
return errCode;
}
WifiOprMidState curState = WifiConfigCenter::GetInstance().GetP2pMidState();
if (curState != WifiOprMidState::CLOSED) {
if (curState == WifiOprMidState::CLOSING) {
return WIFI_OPT_OPEN_FAIL_WHEN_CLOSING;
} else {
return WIFI_OPT_OPEN_SUCC_WHEN_OPENED;
}
}
WifiConfigCenter::GetInstance().SetP2pMidState(curState, WifiOprMidState::OPENING);
ErrCode ret = WIFI_OPT_FAILED;
do {
IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst();
ret = pService->RegisterP2pServiceCallbacks(WifiManager::GetInstance().GetWifiP2pManager()->GetP2pCallback());
ret = pService->EnableP2p();
} while (false);
if (ret != WIFI_OPT_SUCCESS) {
WifiConfigCenter::GetInstance().SetP2pMidState(WifiOprMidState::OPENING, WifiOprMidState::CLOSED);
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_P2P);
} else {
WifiManager::GetInstance().GetWifiP2pManager()->StopUnloadP2PSaTimer();
}
return ret;
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_p2p\p2p_interface.cpp
ErrCode P2pInterface::EnableP2p() {
return p2pService.EnableP2p();
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_p2p\wifi_p2p_service.cpp
ErrCode WifiP2pService::EnableP2p() {
p2pStateMachine.SendMessage(static_cast<int>(P2P_STATE_MACHINE_CMD::CMD_P2P_ENABLE));
return ErrCode::WIFI_OPT_SUCCESS;
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_p2p\p2p_disabled_state.cpp
bool P2pDisabledState::ExecuteStateMsg(InternalMessagePtr msg)
{
switch (static_cast<P2P_STATE_MACHINE_CMD>(msg->GetMessageName())) {
case P2P_STATE_MACHINE_CMD::CMD_P2P_ENABLE: {
/* WifiP2PHalInterface::createP2pInterface */
p2pStateMachine.p2pIface = WifiConfigCenter::GetInstance().GetP2pIfaceName();
bool hasPersisentGroup = p2pStateMachine.HasPersisentGroup();
if (WifiP2PHalInterface::GetInstance().StartP2p(p2pStateMachine.p2pIface,
hasPersisentGroup) == WifiErrorNo::WIFI_HAL_OPT_OK) {
p2pStateMachine.SwitchState(&p2pStateMachine.p2pEnablingState);
} else {
WIFI_LOGE("StartP2p failed.");
p2pStateMachine.SwitchState(&p2pStateMachine.p2pEnablingState);
p2pStateMachine.SendMessage(static_cast<int>(P2P_STATE_MACHINE_CMD::CMD_P2P_DISABLE));
}
break;
}
default:
return NOT_EXECUTED;
}
return EXECUTED;
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_native\wifi_hal_interface\wifi_p2p_hal_interface.cpp
WifiErrorNo WifiP2PHalInterface::StartP2p(const std::string &ifaceName, const bool hasPersisentGroup) const
{
return mHdiWpaClient->ReqP2pStart(ifaceName, hasPersisentGroup);
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_native\client\hdi_client\wifi_hdi_wpa_client.cpp
WifiErrorNo WifiHdiWpaClient::ReqP2pStart(const std::string &ifaceName, const bool hasPersisentGroup)
{
WifiErrorNo ret = HdiWpaP2pStart(ifaceName.c_str(), hasPersisentGroup);
if (ret == WIFI_HAL_OPT_OK) {
OnEventP2pStateChanged(P2P_SUPPLICANT_CONNECTED);
}
return ret;
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_native\client\hdi_client\hdi_interface\wifi_hdi_wpa_p2p_impl.c
WifiErrorNo HdiWpaP2pStart(const char *ifaceName, const bool hasPersisentGroup)
{
char persisentMac[PERSISENT_MAC_LEN] = {0};
bool hasPersisentMac = false;
SetHdiP2pIfaceName(ifaceName);
if (hasPersisentGroup) {
hasPersisentMac = GetOldMac(persisentMac, PERSISENT_MAC_LEN);
}
CopyConfigFile("p2p_supplicant.conf");
if (hasPersisentMac) {
AppendMac(persisentMac, PERSISENT_MAC_LEN);
}
HdiWpaStart(); // 该流程请参考https://laval.csdn.net/6915b4aa82fbe0098cab405e.html中的HdiWpaStart()的流程
RegisterP2pEventCallback();
HdiAddWpaIface(GetHdiP2pIfaceName(), CONFIG_ROOR_DIR"/wpa_supplicant/p2p_supplicant.conf");
return WIFI_HAL_OPT_OK;
}
所在文件:foundation\communication\wifi\wifi\services\wifi_standard\wifi_framework\wifi_manage\wifi_native\client\hdi_client\hdi_interface\wifi_hdi_wpa_proxy.c
WifiErrorNo HdiAddWpaIface(const char *ifName, const char *confName)
{
if (!FindifaceName(ifName)) {
int32_t ret = g_wpaObj->AddWpaIface(g_wpaObj, ifName, confName);
AddIfaceName(ifName);
}
return WIFI_HAL_OPT_OK;
}
所在文件:drivers\peripheral\wlan\wpa\interfaces\hdi_service\service_common\wpa_common_cmd_ext.c
int32_t WpaInterfaceAddWpaIface(struct IWpaInterface *self, const char *ifName, const char *confName)
{
WifiWpaInterface *pWpaInterface = GetWifiWpaGlobalInterface();
AddInterfaceArgv addInterface = {0};
if (strncmp(ifName, "wlan", strlen("wlan")) == 0) {
strcpy_s(addInterface.name, sizeof(addInterface.name) - 1, ifName);
strcpy_s(addInterface.confName, sizeof(addInterface.confName) - 1,
CONFIG_ROOR_DIR"/wpa_supplicant/wpa_supplicant.conf");
} else if (strncmp(ifName, "p2p", strlen("p2p")) == 0) {
strcpy_s(addInterface.name, sizeof(addInterface.name) - 1, ifName);
strcpy_s(addInterface.confName, sizeof(addInterface.confName) - 1,
CONFIG_ROOR_DIR"/wpa_supplicant/p2p_supplicant.conf")
}
pWpaInterface->wpaCliAddIface(pWpaInterface, &addInterface, true);
return HDF_SUCCESS;
}
所在文件:drivers\peripheral\wlan\wpa\interfaces\hdi_service\service_common\hdi_wpa_hal.c
static int WpaCliAddIface(WifiWpaInterface *p, const AddInterfaceArgv *argv, bool isWpaAdd)
{
WpaIfaceInfo *info = p->ifaces;
while (info != NULL) {
if (strncmp(info->name, argv->name, MAX_IFACE_LEN) == 0) {
return 0;
}
info = info->next;
}
if (strncmp(argv->name, P2P_NO_ADD_IFACE_NAME, sizeof(argv->name)) == 0) {
HDF_LOGI("WpaCliAddIface: p2p name is p2p-dev-wlan0, no need add iface");
return 0;
}
info = (WpaIfaceInfo *)calloc(1, sizeof(WpaIfaceInfo));
strcpy_s(info->name, sizeof(info->name), argv->name);
char cmd[WPA_CMD_BUF_LEN] = {0};
char buf[WPA_CMD_REPLY_BUF_SMALL_LEN] = {0};
HDF_LOGI("Add interface start.");
if (isWpaAdd && (snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "INTERFACE_ADD %s\t%s",
argv->name, argv->confName) < 0 || WpaCliCmd(cmd, buf, sizeof(buf)) != 0)) {
free(info);
info = NULL;
HDF_LOGI("WpaCliAddIface failed, cmd: %{public}s, buf: %{public}s", cmd, buf);
return -1;
}
info->next = p->ifaces;
p->ifaces = info;
return 0;
}
更多推荐
所有评论(0)