13 if (str.length() != 17)
return false;
15 for (std::size_t i = 0; i < str.length(); ++i) {
17 if (str[i] !=
':' && str[i] !=
'-')
return false;
19 if (!std::isxdigit(str[i]))
return false;
26 #ifndef MA_HAS_NATTIVE_WIFI_SUPPORT
27 #define MA_HAS_NATTIVE_WIFI_SUPPORT 1
30 #if MA_USE_EXTERNAL_WIFI_STATUS
32 extern in4_info_t _in4_info;
33 extern in6_info_t _in6_info;
34 extern volatile int _net_sta;
36 static in4_info_t _in4_info{};
37 static in6_info_t _in6_info{};
42 static std::string _wifi_ver =
"";
43 static int32_t _wifi_status = 0;
45 #if !MA_HAS_NATTIVE_WIFI_SUPPORT
46 void setWifiVer(
const std::vector<std::string>& argv,
Transport& transport,
Encoder& encoder) {
49 if (argv.size() < 2) {
58 encoder.
write(
"ver", _wifi_ver);
60 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
63 void getWifiVer(
const std::vector<std::string>& argv,
Transport& transport,
Encoder& encoder) {
67 encoder.
write(
"ver", _wifi_ver);
69 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
77 bool is_bssid =
isBssid(argv[1]);
79 if (argv.size() < 4) {
84 if (argv[3].length() < 8) {
90 std::strncpy(config.bssid, argv[1].c_str(),
sizeof(config.bssid) - 1);
92 std::strncpy(config.ssid, argv[1].c_str(),
sizeof(config.ssid) - 1);
94 std::strncpy(config.password, argv[3].c_str(),
sizeof(config.password) - 1);
104 encoder.
write(config);
106 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
109 #if !MA_HAS_NATTIVE_WIFI_SUPPORT
110 void setWifiSta(
const std::vector<std::string>& argv,
Transport& transport,
Encoder& encoder) {
113 if (argv.size() < 2) {
118 _wifi_status = std::atoi(argv[1].c_str());
122 encoder.
write(
"status", _wifi_status);
124 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
127 void setWifiIn4Info(
const std::vector<std::string>& argv,
Transport& transport,
Encoder& encoder) {
130 if (argv.size() < 4) {
136 #if MA_USE_EXTERNAL_WIFI_STATUS
139 _in4_info.ip = ipv4_addr_t::from_str(argv[1]);
140 _in4_info.netmask = ipv4_addr_t::from_str(argv[2]);
141 _in4_info.gateway = ipv4_addr_t::from_str(argv[3]);
147 #if MA_USE_EXTERNAL_WIFI_STATUS
150 encoder.
write(_in4_info);
152 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
155 void setWifiIn6Info(
const std::vector<std::string>& argv,
Transport& transport,
Encoder& encoder) {
158 if (argv.size() < 2) {
164 #if MA_USE_EXTERNAL_WIFI_STATUS
167 _in6_info.ip = ipv6_addr_t::from_str(argv[1]);
172 #if MA_USE_EXTERNAL_WIFI_STATUS
175 encoder.
write(_in6_info);
178 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
193 #if MA_USE_EXTERNAL_WIFI_STATUS
195 _wifi_status = _net_sta > 2 ? 2 : _net_sta;
197 if (std::strlen(config.ssid) < 1) {
200 encoder.
write(_in4_info);
201 encoder.
write(_in6_info);
203 encoder.
write(config, (
int*)&_wifi_status);
205 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
Definition: ma_codec_base.h:14
virtual ma_err_t end()=0
Encoder type for end.
virtual const void * data() const =0
Encoder type for get data.
virtual ma_err_t begin()=0
Encoder type for begin.
virtual ma_err_t write(const std::string &key, int8_t value)=0
Encoder type for write int8_t value.
virtual const size_t size() const =0
Encoder type for get size.
Definition: ma_transport.h:12
virtual size_t send(const char *data, size_t length) noexcept=0
#define MA_STORAGE_KEY_WIFI_PWD
Definition: ma_definations.h:27
#define MA_STORAGE_KEY_WIFI_SECURITY
Definition: ma_definations.h:28
#define MA_STORAGE_KEY_WIFI_SSID
Definition: ma_definations.h:25
#define MA_STORAGE_KEY_WIFI_BSSID
Definition: ma_definations.h:26
ma_wifi_security_t
Definition: ma_types.h:298
@ MA_MSG_TYPE_RESP
Definition: ma_types.h:252
ma_err_t
Definition: ma_types.h:21
@ MA_OK
Definition: ma_types.h:23
@ MA_EINVAL
Definition: ma_types.h:28
Definition: algorithm.hpp:11
void getWifiInfo(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: wifi.hpp:182
void configureWifi(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: wifi.hpp:73
#define static_resource
Definition: resource.hpp:64
Definition: ma_types.h:300
bool isBssid(const std::string &str)
Definition: wifi.hpp:12