lin
2025-08-21 57113df3a0e2be01232281fad9a5f2c060567981
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef __WIFI_COMMAND_H__
#define __WIFI_COMMAND_H__
 
#include "main.h"
#include "nl80211_copy.h"
 
#define SKW_VCMD_GET_CHANNELS                   0x1009
#define SKW_VCMD_SET_COUNTRY                    0x100E
#define SKW_VCMD_GET_VERSION                    0x1403
#define SKW_VCMD_GET_RING_BUFFERS_STATUS        0x1404
#define SKW_VCMD_GET_LOGGER_FEATURES            0x1406
enum SKW_SUBCMD_GET_VERSION {
   SKW_DRV_VERSION = 1,
   SKW_FW_VERSION,
};
 
class WifiCommand {
private:
   struct nl_msg *msg;
   struct nl_sock *sock;
   int id;
 
public:
   WifiCommand(struct nl_sock *sk, int family_id, int flags, int nl80211_cmd);
   wifi_error send();
 
   virtual ~WifiCommand();
   virtual wifi_error build(wifi_interface_handle handle, void *param) = 0;
   // virtual wifi_error parser(struct nl_msg *msg) = 0;
   virtual wifi_error parser(struct nlattr *attr[]) = 0;
   // virtual wifi_error parser(struct nlattr *tb[CTRL_ATTR_MAX])
 
   struct nl_msg *nlmsg()
   {
       return msg;
   }
 
   int put_s8(int attribute, int8_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(int8_t), &value);
   }
 
   int put_u8(int attribute, uint8_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(uint8_t), &value);
   }
 
   int put_s16(int attribute, int16_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(int16_t), &value);
   }
 
   int put_u16(int attribute, uint16_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(uint16_t), &value);
   }
 
   int put_s32(int attribute, int32_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(int32_t), &value);
   }
 
   int put_u32(int attribute, uint32_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(uint32_t), &value);
   }
 
   int put_s64(int attribute, int64_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(int64_t), &value);
   }
 
   int put_u64(int attribute, uint64_t value)
   {
       return nla_put(nlmsg(), attribute, sizeof(uint64_t), &value);
   }
 
   int put_string(int attribute, const char *value)
   {
       return nla_put(nlmsg(), attribute, strlen(value) + 1, value);
   }
 
   int put_addr(int attribute, mac_addr value)
   {
       return nla_put(nlmsg(), attribute, sizeof(mac_addr), value);
   }
 
   struct nlattr *attr_start()
   {
       return nla_nest_start(nlmsg(), NL80211_ATTR_VENDOR_DATA);
   }
 
   void attr_end(struct nlattr *attribute)
   {
       nla_nest_end(nlmsg(), attribute);
   }
};
 
#endif