67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
#include <string.h>
|
|
#include <arpa/inet.h>
|
|
#include "esp_wifi.h"
|
|
#include "esp_log.h"
|
|
|
|
// lwip
|
|
#include "lwip/sys.h"
|
|
#include "lwip/sockets.h"
|
|
#include "lwip/err.h"
|
|
|
|
// custom
|
|
#include "tags.h"
|
|
|
|
int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3) {
|
|
return 0;
|
|
}
|
|
|
|
// convert the string from config to mac
|
|
void convertStringToMac(char* macString, uint8_t *dstArr) {
|
|
int values[6];
|
|
int i;
|
|
// convert the string to uint8_t [6] array
|
|
if (6 == sscanf(macString, "%x:%x:%x:%x:%x:%x",
|
|
&values[0], &values[1], &values[2],
|
|
&values[3], &values[4], &values[5])) {
|
|
/* convert to u8int_t */
|
|
for (i = 0; i < 6; ++i) {
|
|
dstArr[i] = (uint8_t)values[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
void ip2bytes(char ipString[], uint8_t *dstArr) {
|
|
unsigned short a, b, c, d;
|
|
sscanf(ipString, "%hu.%hu.%hu.%hu", &a, &b, &c, &d);
|
|
dstArr[0] = a;
|
|
dstArr[1] = b;
|
|
dstArr[2] = c;
|
|
dstArr[3] = d;
|
|
}
|
|
|
|
void calculateBroadcast(char ipString[], char netmask[], char dstArr[INET_ADDRSTRLEN]) {
|
|
char inetIPStr[INET_ADDRSTRLEN];
|
|
struct in_addr ipArr, maskArr, broadcast;
|
|
|
|
inet_pton(AF_INET, ipString, &ipArr);
|
|
inet_pton(AF_INET, netmask, &maskArr);
|
|
broadcast.s_addr = ipArr.s_addr | ~maskArr.s_addr;
|
|
|
|
inet_ntop(AF_INET, &(broadcast.s_addr), inetIPStr, INET_ADDRSTRLEN);
|
|
|
|
strcpy(dstArr, inetIPStr);
|
|
|
|
ESP_LOGI(TAGSUCC, "broadcast: %s", inetIPStr);
|
|
}
|
|
|
|
void hexDump(const void* data, int len) {
|
|
for(int i=0; i<len; ++i) {
|
|
printf("%02X ", ((unsigned char*)data)[i]);
|
|
}
|
|
}
|
|
|
|
void sendPacket(uint8_t packet[], int packetLen) {
|
|
esp_err_t txStatus = esp_wifi_80211_tx(WIFI_IF_AP, packet, packetLen, false);
|
|
// hexDump(packet, packetLen);
|
|
ESP_LOGI(TAGSUCC, "tx return code: %s", esp_err_to_name(txStatus));
|
|
} |