1 /*
2  * Copyright (C) 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_C_P2P_CONFIG_H
17 #define OHOS_C_P2P_CONFIG_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #ifndef COMMON_MAC_LEN
24 #define COMMON_MAC_LEN 6
25 #endif
26 
27 #define PASSPHRASE_LENGTH 64
28 #define P2P_NAME_LENGTH 33
29 #define INTERFACE_LENGTH 16
30 #define DEVICE_TYPE_LENGTH 128
31 #define MAX_DEVICES_NUM 256
32 #define IP_ADDR_STR_LEN 16
33 
34 typedef enum GroupOwnerBand {
35     GO_BAND_AUTO,
36     GO_BAND_2GHZ,
37     GO_BAND_5GHZ
38 } GroupOwnerBand;
39 
40 typedef struct WifiP2pConfig {
41     unsigned char devAddr[COMMON_MAC_LEN]; /* the device MAC address */
42     int bssidType; /* bssid type */
43     GroupOwnerBand goBand;
44     int netId; /* network id, when -2 means persistent and -1 means temporary, else need >= 0 */
45     char passphrase[PASSPHRASE_LENGTH]; /* the value ranges from 8 to 63. */
46     int groupOwnerIntent; /* the value is -1.(A value of -1 indicates the system can choose an appropriate value.) */
47     char groupName[P2P_NAME_LENGTH]; /* the value ranges from 1 to 32. */
48 } WifiP2pConfig;
49 
50 typedef enum P2pGroupStatus {
51     GS_CREATING,
52     GS_CREATED,
53     GS_STARTED,
54     GS_REMOVING,
55     GS_INVALID
56 } P2pGroupStatus;
57 
58 typedef enum P2pDeviceStatus {
59     PDS_CONNECTED,
60     PDS_INVITED,
61     PDS_FAILED,
62     PDS_AVAILABLE,
63     PDS_UNAVAILABLE
64 } P2pDeviceStatus;
65 
66 typedef enum P2pState {
67     P2P_STATE_NONE = 0,
68     P2P_STATE_IDLE,
69     P2P_STATE_STARTING,
70     P2P_STATE_STARTED,
71     P2P_STATE_CLOSING,
72     P2P_STATE_CLOSED,
73 } P2pState;
74 
75 typedef enum P2pConnectionState {
76     P2P_DISCONNECTED = 0,
77     P2P_CONNECTED,
78 } P2pConnectionState;
79 
80 typedef enum P2pChrEvent {
81     INITIAL_VALUE = 0,
82     GO_NEGOTIATION_PEER_REJECT = 1,
83     GO_NEGOTIATION_WAIT_PEER_READY_TIMEOUT = 2,
84 } P2pChrEvent;
85 
86 typedef struct WifiP2pWfdInfo {
87     int wfdEnabled; /* 0: false, 1: true */
88     int deviceInfo;
89     int ctrlPort;
90     int maxThroughput;
91 } WifiP2pWfdInfo;
92 
93 typedef struct WifiP2pDevice {
94     char deviceName[P2P_NAME_LENGTH]; /* the value range is 0 to 32 characters. */
95     unsigned char devAddr[COMMON_MAC_LEN]; /* the device MAC address */
96     unsigned char randomDevAddr[COMMON_MAC_LEN]; /* the device MAC address */
97     int bssidType; /* bssid type. */
98     char primaryDeviceType[DEVICE_TYPE_LENGTH];
99     char secondaryDeviceType[DEVICE_TYPE_LENGTH];
100     P2pDeviceStatus status;
101     WifiP2pWfdInfo wfdInfo;
102     unsigned int supportWpsConfigMethods;
103     int deviceCapabilitys;
104     int groupCapabilitys;
105     P2pChrEvent chrErrCode;
106 } WifiP2pDevice;
107 
108 typedef struct WifiP2pGroupInfo {
109     WifiP2pDevice owner;
110     int isP2pGroupOwner; /* 0: false, 1: true */
111     char passphrase[PASSPHRASE_LENGTH]; /* the value ranges from 8 to 63. */
112     char interface[INTERFACE_LENGTH];
113     char groupName[P2P_NAME_LENGTH];
114     int networkId;
115     int frequency; /* for example : freq=2412 to select 2.4 GHz channel 1.(Based on 2.4 GHz or 5 GHz) */
116     int isP2pPersistent; /* 0: false, 1: true */
117     P2pGroupStatus groupStatus;
118     WifiP2pDevice clientDevices[MAX_DEVICES_NUM];
119     int clientDevicesSize; /* the true size of clientDevices array */
120     char goIpAddress[IP_ADDR_STR_LEN];
121 } WifiP2pGroupInfo;
122 
123 typedef struct WifiP2pLinkedInfo {
124     P2pConnectionState connectState;
125     int isP2pGroupOwner;
126     unsigned char groupOwnerAddress[COMMON_MAC_LEN];
127 } WifiP2pLinkedInfo;
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif
133