Skip to content

Commit 3eb6ab8

Browse files
authored
added more stubs
1 parent 5a956de commit 3eb6ab8

File tree

3 files changed

+227
-27
lines changed

3 files changed

+227
-27
lines changed

espnet/ap.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ var WiFi = &ESPWiFi{}
2727
type Config struct {
2828
}
2929

30-
var internalConfig = C.wifi_init_config_t{
31-
osi_funcs: &C.g_wifi_osi_funcs,
30+
var internalConfig = C.wifi_init_config_t {
31+
osi_funcs: &C.g_wifi_osi_funcs,
32+
wpa_crypto_funcs: C.g_wifi_default_wpa_crypto_funcs,
33+
static_rx_buf_num: 10,
34+
static_tx_buf_num: 10,
35+
mgmt_sbuf_num: 6,
36+
sta_disconnected_pm: true,
37+
magic: C.WIFI_INIT_CONFIG_MAGIC,
3238
}
3339

3440
func (wifi ESPWiFi) Configure(config Config) error {
41+
C.esp_wifi_internal_set_log_level(5)
3542
return makeError(C.esp_wifi_init_internal(&internalConfig))
3643
}
3744

espnet/espnet.c

+217-25
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
#include <stddef.h>
33
#include <stdio.h>
44
#include <stdlib.h>
5+
#include <string.h>
56
#include "espnet.h"
7+
#include "esp_wifi.h"
68
#include "freertos/FreeRTOS.h"
79
#include "freertos/semphr.h"
810
#include "freertos/task.h"
911

12+
1013
// Stub functions, to know which functions need to be implemented for OS
1114
// functionality.
1215

@@ -33,13 +36,45 @@ static bool _is_from_isr(void) {
3336
printf("called: _is_from_isr\n");
3437
return false;
3538
}
39+
40+
// Having conflict between when include
41+
// #include "freertos/portmacro.h"
42+
43+
typedef struct {
44+
/* owner field values:
45+
* 0 - Uninitialized (invalid)
46+
* portMUX_FREE_VAL - Mux is free, can be locked by either CPU
47+
* CORE_ID_REGVAL_PRO / CORE_ID_REGVAL_APP - Mux is locked to the particular core
48+
*
49+
*
50+
* Any value other than portMUX_FREE_VAL, CORE_ID_REGVAL_PRO, CORE_ID_REGVAL_APP indicates corruption
51+
*/
52+
uint32_t owner;
53+
/* count field:
54+
* If mux is unlocked, count should be zero.
55+
* If mux is locked, count is non-zero & represents the number of recursive locks on the mux.
56+
*/
57+
uint32_t count;
58+
} portMUX_TYPE;
59+
60+
#define portMUX_FREE_VAL SPINLOCK_FREE
61+
#define SPINLOCK_FREE 0xB33FFFFF
62+
63+
#define portMUX_INITIALIZER_UNLOCKED { \
64+
.owner = portMUX_FREE_VAL, \
65+
.count = 0, \
66+
}
67+
3668
static void * _spin_lock_create(void) {
37-
// It looks like the only thing these libraries do, is create and delete
38-
// spin locks. So creating this as a stub for now.
39-
return malloc(1);
69+
portMUX_TYPE tmp = portMUX_INITIALIZER_UNLOCKED;
70+
void *mux = malloc(sizeof(portMUX_TYPE));
71+
if (mux) {
72+
memcpy(mux,&tmp,sizeof(portMUX_TYPE));
73+
return mux;
74+
}
75+
return NULL;
4076
}
4177
static void _spin_lock_delete(void *lock) {
42-
// See _spin_lock_create.
4378
free(lock);
4479
}
4580
static uint32_t _wifi_int_disable(void *wifi_int_mux) {
@@ -193,10 +228,6 @@ static void _phy_disable(void) {
193228
static void _phy_enable(void) {
194229
P(_phy_enable)
195230
}
196-
// #if CONFIG_IDF_TARGET_ESP32
197-
// void (* _phy_common_clock_enable(void)
198-
// void (* _phy_common_clock_disable(void)
199-
// #endif
200231
static int _phy_update_country_info(const char* country) {
201232
P(_phy_update_country_info)
202233
return 0;
@@ -299,39 +330,48 @@ static unsigned long _random(void) {
299330
return 0;
300331
}
301332
// #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
302-
// uint32_t (* _slowclk_cal_get(void)
333+
// uint32_t (* _slowclk_cal_get(void)
303334
// #endif
304335
static void _log_write(uint32_t level, const char* tag, const char* format, ...) {
305-
P(_log_write)
336+
va_list argList;
337+
printf("[%s] ", tag);
338+
va_start(argList, format);
339+
vprintf(format, argList);
340+
va_end(argList);
341+
printf("\n");
306342
}
307343
static void _log_writev(uint32_t level, const char* tag, const char* format, va_list args) {
308-
P(_log_writev)
344+
printf("[%s] ", tag);
345+
vprintf(format, args);
346+
printf("\n");
309347
}
348+
310349
static uint32_t _log_timestamp(void) {
311350
P(_log_timestamp)
312351
return 0;
313352
}
314353
static void* _malloc_internal(size_t size) {
315-
P(_malloc_internal)
316-
return NULL;
354+
printf("called: _malloc_internal(%d)\n", size);
355+
return malloc(size);
317356
}
318357
static void* _realloc_internal(void *ptr, size_t size) {
319-
P(_realloc_internal)
358+
printf("called: _realloc_internal(%p,%d)\n", ptr, size);
320359
return NULL;
321360
}
361+
322362
static void* _calloc_internal(size_t n, size_t size) {
323-
P(_calloc_internal)
324-
return NULL;
363+
printf("called: _calloc_internal(%d,%d)\n", n, size);
364+
return malloc(n * size);
325365
}
326366
static void* _zalloc_internal(size_t size) {
327-
P(_zalloc_internal)
367+
printf("called: _zalloc_internal(%d)\n", size);
328368
return NULL;
329369
}
330370
static void* _wifi_malloc(size_t size) {
331371
return malloc(size);
332372
}
333373
static void* _wifi_realloc(void *ptr, size_t size) {
334-
P(_wifi_realloc)
374+
printf("called: _wifi_realloc(%d)\n", size);
335375
return NULL;
336376
}
337377
static void* _wifi_calloc(size_t n, size_t size) {
@@ -419,6 +459,11 @@ static int _coex_schm_curr_phase_idx_get(void) {
419459
return 0;
420460
}
421461

462+
463+
uint32_t _slowclk_cal_get(void) {
464+
return 0;
465+
}
466+
422467
// OS adapter functions.
423468
// See: esp-idf/components/esp_wifi/include/esp_private/wifi_os_adapter.h
424469
wifi_osi_funcs_t g_wifi_osi_funcs = {
@@ -476,10 +521,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
476521
._wifi_apb80m_release = _wifi_apb80m_release,
477522
._phy_disable = _phy_disable,
478523
._phy_enable = _phy_enable,
479-
// #if CONFIG_IDF_TARGET_ESP32
480-
// void (* _phy_common_clock_enable
481-
// void (* _phy_common_clock_disable
482-
// #endif
483524
._phy_update_country_info = _phy_update_country_info,
484525
._read_mac = _read_mac,
485526
._timer_arm = _timer_arm,
@@ -508,9 +549,9 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
508549
._get_random = _get_random,
509550
._get_time = _get_time,
510551
._random = _random,
511-
// #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
512-
// uint32_t (* _slowclk_cal_get
513-
// #endif
552+
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
553+
._slowclk_cal_get = _slowclk_cal_get,
554+
#endif
514555
._log_write = _log_write,
515556
._log_writev = _log_writev,
516557
._log_timestamp = _log_timestamp,
@@ -547,6 +588,157 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
547588
._magic = ESP_WIFI_OS_ADAPTER_MAGIC,
548589
};
549590

591+
static int esp_aes_wrap(const unsigned char *kek, int n, const unsigned char *plain, unsigned char *cipher) {
592+
P(aes_wrap)
593+
return -1;
594+
}
595+
static int esp_aes_unwrap(const unsigned char *kek, int n, const unsigned char *cipher, unsigned char *plain) {
596+
P(aes_unwrap)
597+
return -1;
598+
}
599+
static int hmac_sha256_vector(const unsigned char *key, int key_len, int num_elem,
600+
const unsigned char *addr[], const int *len, unsigned char *mac) {
601+
return -1;
602+
}
603+
static int sha256_prf(const unsigned char *key, int key_len, const char *label,
604+
const unsigned char *data, int data_len, unsigned char *buf, int buf_len) {
605+
P(sha256_prf)
606+
return -1;
607+
}
608+
static int hmac_md5(const unsigned char *key, unsigned int key_len, const unsigned char *data,
609+
unsigned int data_len, unsigned char *mac) {
610+
P(hmac_md5)
611+
return -1;
612+
}
613+
static int hamc_md5_vector(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
614+
const unsigned char *addr[], const unsigned int *len, unsigned char *mac) {
615+
P(hamc_md5_vector)
616+
return -1;
617+
}
618+
static int hmac_sha1(const unsigned char *key, unsigned int key_len, const unsigned char *data,
619+
unsigned int data_len, unsigned char *mac) {
620+
P(hmac_sha1)
621+
return -1;
622+
}
623+
static int hmac_sha1_vector(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
624+
const unsigned char *addr[], const unsigned int *len, unsigned char *mac) {
625+
P(hmac_sha1_vector)
626+
return -1;
627+
}
628+
static int sha1_prf(const unsigned char *key, unsigned int key_len, const char *label,
629+
const unsigned char *data, unsigned int data_len, unsigned char *buf, unsigned int buf_len) {
630+
P(sha1_prf)
631+
return -1;
632+
}
633+
static int sha1_vector(unsigned int num_elem, const unsigned char *addr[], const unsigned int *len,
634+
unsigned char *mac) {
635+
P(sha1_vector)
636+
return -1;
637+
}
638+
static int pbkdf2_sha1(const char *passphrase, const char *ssid, unsigned int ssid_len,
639+
int iterations, unsigned char *buf, unsigned int buflen) {
640+
P(pbkdf2_sha1)
641+
return -1;
642+
}
643+
static int rc4_skip(const unsigned char *key, unsigned int keylen, unsigned int skip,
644+
unsigned char *data, unsigned int data_len) {
645+
P(rc4_skip)
646+
return -1;
647+
}
648+
static int md5_vector(unsigned int num_elem, const unsigned char *addr[], const unsigned int *len,
649+
unsigned char *mac) {
650+
P(md5_vector)
651+
return -1;
652+
}
653+
static void aes_encrypt(void *ctx, const unsigned char *plain, unsigned char *crypt) {
654+
P(aes_encrypt)
655+
}
656+
static void * aes_encrypt_init(const unsigned char *key, unsigned int len) {
657+
P(aes_encrypt_init)
658+
return NULL;
659+
}
660+
static void aes_encrypt_deinit(void *ctx) {
661+
P(aes_encrypt_deinit)
662+
}
663+
static void aes_decrypt(void *ctx, const unsigned char *crypt, unsigned char *plain) {
664+
P(aes_decrypt)
665+
}
666+
static void * aes_decrypt_init(const unsigned char *key, unsigned int len) {
667+
P(aes_decrypt_init)
668+
return NULL;
669+
}
670+
static void aes_decrypt_deinit(void *ctx) {
671+
P(aes_decrypt_deinit)
672+
}
673+
static int aes_128_decrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len) {
674+
P(aes_128_decrypt)
675+
return -1;
676+
}
677+
static int omac1_aes_128(const uint8_t *key, const uint8_t *data, size_t data_len,
678+
uint8_t *mic) {
679+
P(omac1_aes_128)
680+
return -1;
681+
}
682+
static uint8_t * ccmp_decrypt(const uint8_t *tk, const uint8_t *ieee80211_hdr,
683+
const uint8_t *data, size_t data_len,
684+
size_t *decrypted_len, bool espnow_pkt) {
685+
P(ccmp_decrypt)
686+
return NULL;
687+
}
688+
static uint8_t * ccmp_encrypt(const uint8_t *tk, uint8_t *frame, size_t len, size_t hdrlen,
689+
uint8_t *pn, int keyid, size_t *encrypted_len) {
690+
P(ccmp_encrypt)
691+
return NULL;
692+
}
693+
static int hmac_md5_vector(const unsigned char *key, unsigned int key_len, unsigned int num_elem,
694+
const unsigned char *addr[], const unsigned int *len, unsigned char *mac) {
695+
P(hmac_md5_vector)
696+
return -1;
697+
}
698+
static void esp_aes_encrypt(void *ctx, const unsigned char *plain, unsigned char *crypt) {
699+
P(esp_aes_encrypt)
700+
}
701+
static void esp_aes_decrypt(void *ctx, const unsigned char *crypt, unsigned char *plain) {
702+
P(esp_aes_decrypt)
703+
}
704+
static int aes_128_cbc_encrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len) {
705+
P(aes_128_cbc_encrypt)
706+
return -1;
707+
}
708+
static int aes_128_cbc_decrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len) {
709+
P(aes_128_cbc_decrypt)
710+
return -1;
711+
}
712+
713+
const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = {
714+
.size = sizeof(wpa_crypto_funcs_t),
715+
.version = ESP_WIFI_CRYPTO_VERSION,
716+
.aes_wrap = (esp_aes_wrap_t)esp_aes_wrap,
717+
.aes_unwrap = (esp_aes_unwrap_t)esp_aes_unwrap,
718+
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)hmac_sha256_vector,
719+
.sha256_prf = (esp_sha256_prf_t)sha256_prf,
720+
.hmac_md5 = (esp_hmac_md5_t)hmac_md5,
721+
.hamc_md5_vector = (esp_hmac_md5_vector_t)hmac_md5_vector,
722+
.hmac_sha1 = (esp_hmac_sha1_t)hmac_sha1,
723+
.hmac_sha1_vector = (esp_hmac_sha1_vector_t)hmac_sha1_vector,
724+
.sha1_prf = (esp_sha1_prf_t)sha1_prf,
725+
.sha1_vector = (esp_sha1_vector_t)sha1_vector,
726+
.pbkdf2_sha1 = (esp_pbkdf2_sha1_t)pbkdf2_sha1,
727+
.rc4_skip = (esp_rc4_skip_t)rc4_skip,
728+
.md5_vector = (esp_md5_vector_t)md5_vector,
729+
.aes_encrypt = (esp_aes_encrypt_t)esp_aes_encrypt,
730+
.aes_encrypt_init = (esp_aes_encrypt_init_t)aes_encrypt_init,
731+
.aes_encrypt_deinit = (esp_aes_encrypt_deinit_t)aes_encrypt_deinit,
732+
.aes_decrypt = (esp_aes_decrypt_t)esp_aes_decrypt,
733+
.aes_decrypt_init = (esp_aes_decrypt_init_t)aes_decrypt_init,
734+
.aes_decrypt_deinit = (esp_aes_decrypt_deinit_t)aes_decrypt_deinit,
735+
.aes_128_encrypt = (esp_aes_128_encrypt_t)aes_128_cbc_encrypt,
736+
.aes_128_decrypt = (esp_aes_128_decrypt_t)aes_128_cbc_decrypt,
737+
.omac1_aes_128 = (esp_omac1_aes_128_t)omac1_aes_128,
738+
.ccmp_decrypt = (esp_ccmp_decrypt_t)ccmp_decrypt,
739+
.ccmp_encrypt = (esp_ccmp_encrypt_t)ccmp_encrypt
740+
};
741+
550742
// This is a string constant that is used all over ESP-IDF and is also used by
551743
// libnet80211.a. The main purpose is to be a fixed pointer that can be compared
552744
// against etc.

espnet/espnet.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdbool.h>
2+
23
#include "esp_private/wifi_os_adapter.h"
34

45
extern wifi_osi_funcs_t g_wifi_osi_funcs;

0 commit comments

Comments
 (0)