2
2
#include <stddef.h>
3
3
#include <stdio.h>
4
4
#include <stdlib.h>
5
+ #include <string.h>
5
6
#include "espnet.h"
7
+ #include "esp_wifi.h"
6
8
#include "freertos/FreeRTOS.h"
7
9
#include "freertos/semphr.h"
8
10
#include "freertos/task.h"
9
11
12
+
10
13
// Stub functions, to know which functions need to be implemented for OS
11
14
// functionality.
12
15
@@ -33,13 +36,45 @@ static bool _is_from_isr(void) {
33
36
printf ("called: _is_from_isr\n" );
34
37
return false;
35
38
}
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
+
36
68
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 ;
40
76
}
41
77
static void _spin_lock_delete (void * lock ) {
42
- // See _spin_lock_create.
43
78
free (lock );
44
79
}
45
80
static uint32_t _wifi_int_disable (void * wifi_int_mux ) {
@@ -193,10 +228,6 @@ static void _phy_disable(void) {
193
228
static void _phy_enable (void ) {
194
229
P (_phy_enable )
195
230
}
196
- // #if CONFIG_IDF_TARGET_ESP32
197
- // void (* _phy_common_clock_enable(void)
198
- // void (* _phy_common_clock_disable(void)
199
- // #endif
200
231
static int _phy_update_country_info (const char * country ) {
201
232
P (_phy_update_country_info )
202
233
return 0 ;
@@ -299,39 +330,48 @@ static unsigned long _random(void) {
299
330
return 0 ;
300
331
}
301
332
// #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)
303
334
// #endif
304
335
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" );
306
342
}
307
343
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" );
309
347
}
348
+
310
349
static uint32_t _log_timestamp (void ) {
311
350
P (_log_timestamp )
312
351
return 0 ;
313
352
}
314
353
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 ) ;
317
356
}
318
357
static void * _realloc_internal (void * ptr , size_t size ) {
319
- P ( _realloc_internal )
358
+ printf ( "called: _realloc_internal(%p,%d)\n" , ptr , size );
320
359
return NULL ;
321
360
}
361
+
322
362
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 ) ;
325
365
}
326
366
static void * _zalloc_internal (size_t size ) {
327
- P ( _zalloc_internal )
367
+ printf ( "called: _zalloc_internal(%d)\n" , size );
328
368
return NULL ;
329
369
}
330
370
static void * _wifi_malloc (size_t size ) {
331
371
return malloc (size );
332
372
}
333
373
static void * _wifi_realloc (void * ptr , size_t size ) {
334
- P ( _wifi_realloc )
374
+ printf ( "called: _wifi_realloc(%d)\n" , size );
335
375
return NULL ;
336
376
}
337
377
static void * _wifi_calloc (size_t n , size_t size ) {
@@ -419,6 +459,11 @@ static int _coex_schm_curr_phase_idx_get(void) {
419
459
return 0 ;
420
460
}
421
461
462
+
463
+ uint32_t _slowclk_cal_get (void ) {
464
+ return 0 ;
465
+ }
466
+
422
467
// OS adapter functions.
423
468
// See: esp-idf/components/esp_wifi/include/esp_private/wifi_os_adapter.h
424
469
wifi_osi_funcs_t g_wifi_osi_funcs = {
@@ -476,10 +521,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
476
521
._wifi_apb80m_release = _wifi_apb80m_release ,
477
522
._phy_disable = _phy_disable ,
478
523
._phy_enable = _phy_enable ,
479
- // #if CONFIG_IDF_TARGET_ESP32
480
- // void (* _phy_common_clock_enable
481
- // void (* _phy_common_clock_disable
482
- // #endif
483
524
._phy_update_country_info = _phy_update_country_info ,
484
525
._read_mac = _read_mac ,
485
526
._timer_arm = _timer_arm ,
@@ -508,9 +549,9 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
508
549
._get_random = _get_random ,
509
550
._get_time = _get_time ,
510
551
._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
514
555
._log_write = _log_write ,
515
556
._log_writev = _log_writev ,
516
557
._log_timestamp = _log_timestamp ,
@@ -547,6 +588,157 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
547
588
._magic = ESP_WIFI_OS_ADAPTER_MAGIC ,
548
589
};
549
590
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
+
550
742
// This is a string constant that is used all over ESP-IDF and is also used by
551
743
// libnet80211.a. The main purpose is to be a fixed pointer that can be compared
552
744
// against etc.
0 commit comments