• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
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 WIFI_IOCTL_H
17 #define WIFI_IOCTL_H
18 
19 #include <net/if.h>
20 #include <arpa/inet.h>
21 #include <dirent.h>
22 #include <netlink-private/types.h>
23 #include <netlink/genl/ctrl.h>
24 #include <netlink/genl/genl.h>
25 #include <netlink/handlers.h>
26 #include <linux/version.h>
27 #include <securec.h>
28 #include <cstdio>
29 #include <sys/ioctl.h>
30 #include <sys/socket.h>
31 #include <sys/time.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 
35 #define PRIMARY_ID_POWER_MODE   0x8bfd
36 #define SECONDARY_ID_POWER_MODE 0x101
37 #define SET_POWER_MODE_SLEEP     "pow_mode sleep"
38 #define SET_POWER_MODE_INIT      "pow_mode init"
39 #define SET_POWER_MODE_THIRD     "pow_mode third"
40 #define GET_POWER_MODE           "get_pow_mode"
41 #define CMD_SET_STA_PM_ON        "SET_STA_PM_ON"
42 #define CMD_WIFI_CATEGORY "CMD_WIFI_CATEGORY"
43 #define CMD_GET_WIFI_PRIV_FEATURE_CAPABILITY "GET_WIFI_PRIV_FEATURE_CAPABILITY"
44 #define WIFI_POWER_MODE_SLEEPING 0
45 #define WIFI_POWER_MODE_GENERAL 1
46 #define WIFI_POWER_MODE_THROUGH_WALL 2
47 #define WIFI_POWER_MODE_NUM 3
48 #define MAX_CMD_LEN 64
49 #define MAX_PRIV_CMD_SIZE 4096
50 #ifndef KERNEL_VERSION
51 #define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + ((c) > 255 ? 255 : (c)))
52 #endif
53 
54 typedef struct {
55     void *buf;
56     uint16_t length;
57     uint16_t flags;
58 } DataPoint;
59 
60 union HwprivReqData {
61     char name[IFNAMSIZ];
62     int32_t mode;
63     DataPoint point;
64 };
65 
66 typedef struct {
67     char interfaceName[IFNAMSIZ];
68     union HwprivReqData data;
69 } HwprivIoctlData;
70 
71 typedef struct {
72 #if (defined(LINUX_VERSION_CODE) && LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0))
73     uint8_t *buf;
74     uint32_t size;
75     uint32_t len;
76 #else
77     uint32_t size;
78     uint32_t len;
79     uint8_t *buf;
80 #endif
81 } WifiPrivCmd;
82 
83 WifiError GetPowerMode(const char *ifName, int *mode);
84 WifiError SetPowerMode(const char *ifName, int mode);
85 WifiError EnablePowerMode(const char *ifName, int mode);
86 uint32_t GetChipCaps(const char *ifName);
87 uint32_t WifiGetSupportedFeatureSet(const char *ifName);
88 WifiError SetTxPower(const char *ifName, int mode);
89 
90 #endif
91