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