@@ -30,6 +30,7 @@ static EventGroupHandle_t s_event_group = NULL;
30
30
static const char * TAG = "eppp_link" ;
31
31
static int s_retry_num = 0 ;
32
32
static int s_eppp_netif_count = 0 ; // used as a suffix for the netif key
33
+ static eppp_channel_fn_t s_rx = NULL ;
33
34
34
35
struct eppp_handle {
35
36
#if CONFIG_EPPP_LINK_DEVICE_SPI
@@ -52,8 +53,28 @@ struct eppp_handle {
52
53
struct packet {
53
54
size_t len ;
54
55
uint8_t * data ;
56
+ int channel ;
55
57
};
56
58
59
+ static esp_err_t transmit_channel (void * netif , void * buffer , size_t len )
60
+ {
61
+ struct eppp_handle * h = esp_netif_get_io_driver (netif );
62
+ struct packet buf = { .len = len };
63
+ buf .channel = 1 ;
64
+ buf .data = malloc (len );
65
+ if (buf .data == NULL ) {
66
+ ESP_LOGE (TAG , "Failed to allocate packet" );
67
+ return ESP_FAIL ;
68
+ }
69
+ memcpy (buf .data , buffer , len );
70
+ BaseType_t ret = xQueueSend (h -> out_queue , & buf , pdMS_TO_TICKS (10 ));
71
+ if (ret != pdTRUE ) {
72
+ ESP_LOGE (TAG , "Failed to queue packet to slave!" );
73
+ return ESP_FAIL ;
74
+ }
75
+ return ESP_OK ;
76
+ }
77
+
57
78
static esp_err_t transmit (void * h , void * buffer , size_t len )
58
79
{
59
80
struct eppp_handle * handle = h ;
@@ -230,6 +251,10 @@ static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void
230
251
{
231
252
ip_event_got_ip_t * event = (ip_event_got_ip_t * )data ;
232
253
esp_netif_t * netif = event -> esp_netif ;
254
+ if (event_id == IP_EVENT_STA_GOT_IP ) {
255
+ ESP_LOGI (TAG , "Got IPv4 event: Interface \"%s(%s)\" address: " IPSTR , esp_netif_get_desc (netif ),
256
+ esp_netif_get_ifkey (netif ), IP2STR (& event -> ip_info .ip ));
257
+ }
233
258
int netif_cnt = get_netif_num (netif );
234
259
if (netif_cnt < 0 ) {
235
260
return ;
@@ -275,6 +300,7 @@ struct header {
275
300
} __attribute__((packed ));
276
301
};
277
302
uint8_t magic ;
303
+ uint8_t channel ;
278
304
uint8_t checksum ;
279
305
} __attribute__((packed ));
280
306
@@ -452,6 +478,13 @@ static esp_err_t perform_transaction_slave(union transaction *t, struct eppp_han
452
478
return spi_slave_transmit (h -> spi_host , & t -> slave , portMAX_DELAY );
453
479
}
454
480
481
+ esp_err_t eppp_add_channel (int nr , eppp_channel_fn_t * tx , const eppp_channel_fn_t rx )
482
+ {
483
+ * tx = transmit_channel ;
484
+ s_rx = rx ;
485
+ return ESP_OK ;
486
+ }
487
+
455
488
esp_err_t eppp_perform (esp_netif_t * netif )
456
489
{
457
490
static WORD_ALIGNED_ATTR uint8_t out_buf [TRANSFER_SIZE ] = {};
@@ -482,8 +515,10 @@ esp_err_t eppp_perform(esp_netif_t *netif)
482
515
head -> magic = FRAME_OUT_CTRL_EX ;
483
516
head -> size = 0 ;
484
517
head -> checksum = 0 ;
518
+ head -> channel = 0 ;
485
519
BaseType_t tx_queue_stat = xQueueReceive (h -> out_queue , & buf , 0 );
486
520
if (tx_queue_stat == pdTRUE && buf .data ) {
521
+ head -> channel = buf .channel ;
487
522
if (buf .len > SHORT_PAYLOAD ) {
488
523
head -> magic = FRAME_OUT_CTRL ;
489
524
head -> size = buf .len ;
@@ -521,7 +556,14 @@ esp_err_t eppp_perform(esp_netif_t *netif)
521
556
return ESP_FAIL ;
522
557
}
523
558
if (head -> magic == FRAME_IN_CTRL_EX && head -> short_size > 0 ) {
524
- esp_netif_receive (netif , in_buf + sizeof (struct header ), head -> short_size , NULL );
559
+ if (head -> channel == 0 ) {
560
+ esp_netif_receive (netif , in_buf + sizeof (struct header ), head -> short_size , NULL );
561
+ } else {
562
+ ESP_LOGE (TAG , "Got channel %d size %d" , head -> channel , head -> short_size );
563
+ if (s_rx != NULL ) {
564
+ s_rx (netif , in_buf + sizeof (struct header ), head -> short_size );
565
+ }
566
+ }
525
567
}
526
568
size_t in_long_payload = 0 ;
527
569
if (head -> magic == FRAME_IN_CTRL ) {
@@ -537,6 +579,7 @@ esp_err_t eppp_perform(esp_netif_t *netif)
537
579
head -> magic = FRAME_OUT_DATA ;
538
580
head -> size = out_long_payload ;
539
581
head -> checksum = 0 ;
582
+ head -> channel = buf .channel ;
540
583
for (int i = 0 ; i < sizeof (struct header ) - 1 ; ++ i ) {
541
584
head -> checksum += out_buf [i ];
542
585
}
@@ -570,7 +613,14 @@ esp_err_t eppp_perform(esp_netif_t *netif)
570
613
571
614
if (head -> size > 0 ) {
572
615
ESP_LOG_BUFFER_HEXDUMP (TAG , in_buf + sizeof (struct header ), head -> size , ESP_LOG_VERBOSE );
573
- esp_netif_receive (netif , in_buf + sizeof (struct header ), head -> size , NULL );
616
+ if (head -> channel == 0 ) {
617
+ esp_netif_receive (netif , in_buf + sizeof (struct header ), head -> size , NULL );
618
+ } else {
619
+ ESP_LOGE (TAG , "Got channel %d size %d" , head -> channel , head -> size );
620
+ if (s_rx != NULL ) {
621
+ s_rx (netif , in_buf + sizeof (struct header ), head -> size );
622
+ }
623
+ }
574
624
}
575
625
return ESP_OK ;
576
626
}
0 commit comments