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 P2PLINK_TYPE_H 17 #define P2PLINK_TYPE_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif 27 28 #define GROUP_CONFIG_LEN 128 29 #define CHAN_LIST_LEN 256 30 #define P2P_MAC_LEN 32 31 #define P2PLINK_INTERFACE_LEN 64 32 #define P2P_IP_LEN 48 33 #define WIFI_CONFIG_DATA_LEN 256 34 #define CHAN_SCORE_LEN 64 35 #define P2PLINK_WIFICFG_LEN 256 36 #define MAX_GROUP_CONFIG_ITEM_NUM 5 37 #define GROUP_CONFIG_ITEM_NUM 4 38 39 #define KEY_COMMAND_TYPE "KEY_COMMAND_TYPE" // request msg common 40 #define KEY_VERSION "KEY_VERSION" 41 #define KEY_ROLE "KEY_ROLE" 42 #define KEY_MAC "KEY_MAC" 43 #define KEY_EXPECTED_ROLE "KEY_EXPECTED_ROLE" 44 #define KEY_SELF_WIFI_CONFIG "KEY_SELF_WIFI_CONFIG" 45 #define KEY_BRIDGE_SUPPORTED "KEY_BRIDGE_SUPPORTED" 46 #define KEY_IP "KEY_IP" // response msg common 47 #define KEY_CONTENT_TYPE "KEY_CONTENT_TYPE" // go, gc and result 48 #define KEY_RESULT "KEY_RESULT" // result 49 50 #define KEY_GROUP_CONFIG "KEY_GROUP_CONFIG" // go msg 51 #define KEY_GO_IP "KEY_GO_IP" 52 #define KEY_GC_IP "KEY_GC_IP" 53 #define KEY_GO_PORT "KEY_GO_PORT" 54 55 #define KEY_WIDE_BAND_SUPPORTED "KEY_WIDE_BAND_SUPPORTED" // gc msg 56 #define KEY_GC_CHANNEL_LIST "KEY_GC_CHANNEL_LIST" 57 #define KEY_STATION_FREQUENCY "KEY_STATION_FREQUENCY" 58 #define KEY_GC_CHANNEL_SCORE "KEY_GC_CHANNEL_SCORE" 59 60 #define KEY_GO_MAC "KEY_GO_MAC" // go and gc common msg 61 #define KEY_GC_MAC "KEY_GC_MAC" 62 63 // msg errcode 64 #define P2PLINK_OK 0 65 #define ERROR_CONNECTED_WITH_MISMATCHED_ROLE (-1) 66 #define ERROR_GC_CONNECTED_TO_ANOTHER_DEVICE (-2) 67 #define ERROR_AVAILABLE_WITH_MISMATCHED_ROLE (-3) 68 #define ERROR_PEER_GC_CONNECTED_TO_ANOTHER_DEVICE (-4) 69 #define ERROR_BOTH_GO (-5) 70 #define ERROR_TWO_WAY_SIMULTANEOUS_CONNECTION (-6) 71 #define ERROR_CONNECT_TIMEOUT (-7) 72 #define ERROR_REUSE_FAILED (-8) 73 #define ERROR_LINK_USED_BY_ANOTHER_SERVICE (-9) 74 #define ERROR_WRONG_GO_INFO (-10) 75 #define ERROR_WRONG_GC_INFO (-11) 76 #define ERROR_POST_MESSAGE_FAILED (-12) 77 #define ERROR_BUSY (-15) 78 #define ERROR_NOT_TRUSTED_DEVICE (-17) 79 #define ERROR_CONNECT_GROUP_FAILED (-18) 80 #define ERROR_CREATE_GROUP_FAILED (-19) 81 #define ERROR_PEER_CONNECT_GROUP_FAILED (-20) 82 #define ERROR_PEER_CREATE_GROUP_FAILED (-21) 83 #define ERROR_RPT_ENABLED (-22) 84 #define ERROR_PEER_RPT_ENABLED (-23) 85 86 #define TIMEOUT_WAIT_REUSE 2 87 88 typedef enum { 89 NEED_POST_DISCONNECT = -2000, 90 NOT_SUPPORT_BRIDGE, 91 POST_REQUEST_MSG_FAILED, 92 POST_RESPONSE_MSG_FAILED, 93 P2PLINK_OPEN_P2P_AUTHCHAN_FAIL, 94 P2PLINK_P2P_AUTHCHAN_NOTIFY_FAIL, 95 P2PLINK_P2P_SEND_REUSEFAIL, 96 P2PLINK_P2P_MALLOCFAIL, 97 P2PLINK_P2P_CLEAN, 98 P2PLINK_P2P_STATE_CLOSE, 99 MAGICLINK_CONFIGIP_FAILED, 100 UNEXPECTED_CONTENT_TYPE, 101 ROLE_NEG_TIME_OUT, 102 MAGICLINK_DHCP_TIME_OUT, 103 WAIT_RESPONSE_MSG_TIME_OUT, 104 } P2pLinkErrCode; 105 106 typedef struct { 107 char groupConfig[GROUP_CONFIG_LEN]; 108 char goMac[P2P_MAC_LEN]; 109 char goIp[P2P_IP_LEN]; 110 char gcMac[P2P_MAC_LEN]; 111 char gcIp[P2P_IP_LEN]; 112 int32_t goPort; 113 } GoInfo; 114 115 typedef struct { 116 char channelList[CHAN_LIST_LEN]; 117 char gcMac[P2P_MAC_LEN]; 118 char goMac[P2P_IP_LEN]; 119 char channelScore[CHAN_SCORE_LEN]; 120 int32_t stationFrequency; 121 bool isWideBandSupported; 122 } GcInfo; 123 124 typedef enum { 125 ROLE_AUTO = 1, 126 ROLE_GO, 127 ROLE_GC, 128 ROLE_BRIDGE_GC, 129 ROLE_NONE, 130 } P2pLinkRole; 131 132 typedef enum { 133 CMD_START = 1, 134 CMD_STOP, 135 CMD_NEXT_COMMAND, 136 CMD_CONNECT_COMMAND, 137 CMD_DISCONNECT_COMMAND, 138 CMD_REQUEST_INFO, 139 CMD_RESPONSE_INFO, 140 CMD_CONNECT_REQUEST, 141 CMD_CONNECT_RESPONSE, 142 CMD_CONNECTION_CHANGED, 143 CMD_CONNECT_STATE_CHANGED, 144 CMD_REUSE, 145 CMD_CTRL_CHL_HANDSHAKE, 146 CMD_DISCONNECT_REQUEST, 147 CMD_CONNECTION_DISABLED, 148 CMD_KEY_PEER_WIFI_CONFIG, 149 CMD_GC_WIFI_CONFIG_STATE_CHANGE, 150 CMD_GC_WIFI_CONFIG_DHCP_IP, 151 CMD_REUSE_RESPONSE, 152 CMD_WAIT_GC_CONNECT_RELEASE, 153 } P2pLinkCmdType; 154 155 #ifdef __cplusplus 156 #if __cplusplus 157 } 158 #endif /* __cplusplus */ 159 #endif /* __cplusplus */ 160 161 #endif