| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  |  * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: Apache-2.0 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include <esp_private/wifi.h>
 | 
					
						
							|  |  |  | #include "esp_err.h"
 | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  | #include "esp_wifi_remote.h"
 | 
					
						
							|  |  |  | #include "esp_log.h"
 | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define CHANNELS 2
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | #define WEAK __attribute__((weak))
 | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  | static esp_remote_channel_tx_fn_t s_tx_cb[CHANNELS]; | 
					
						
							|  |  |  | static esp_remote_channel_t s_channel[CHANNELS]; | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | static wifi_rxcb_t s_rx_fn[CHANNELS]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | WEAK esp_err_t esp_wifi_remote_channel_rx(void *h, void *buffer, void *buff_to_free, size_t len) | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  |     assert(h); | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  |     if (h == s_channel[0] && s_rx_fn[0]) { | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  |         return s_rx_fn[0](buffer, len, buff_to_free); | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  |     if (h == s_channel[1] && s_rx_fn[1]) { | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  |         return s_rx_fn[1](buffer, len, buff_to_free); | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     return ESP_FAIL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | WEAK esp_err_t esp_wifi_remote_channel_set(wifi_interface_t ifx, void *h, esp_remote_channel_tx_fn_t tx_cb) | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (ifx == WIFI_IF_STA) { | 
					
						
							|  |  |  |         s_channel[0] = h; | 
					
						
							|  |  |  |         s_tx_cb[0] = tx_cb; | 
					
						
							|  |  |  |         return ESP_OK; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (ifx == WIFI_IF_AP) { | 
					
						
							|  |  |  |         s_channel[1] = h; | 
					
						
							|  |  |  |         s_tx_cb[1] = tx_cb; | 
					
						
							|  |  |  |         return ESP_OK; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ESP_FAIL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | WEAK esp_err_t esp_wifi_internal_set_sta_ip(void) | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  |     // TODO: Pass this information to the slave target
 | 
					
						
							|  |  |  |     // Note that this function is called from the default event loop, so we shouldn't block here
 | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  |     return ESP_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | WEAK esp_err_t esp_wifi_internal_reg_netstack_buf_cb(wifi_netstack_buf_ref_cb_t ref, wifi_netstack_buf_free_cb_t free) | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return ESP_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | WEAK void esp_wifi_internal_free_rx_buffer(void *buffer) | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  |     free(buffer); | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-21 15:24:16 +08:00
										 |  |  | WEAK esp_err_t esp_wifi_internal_tx_by_ref(wifi_interface_t ifx, void *buffer, size_t len, void *netstack_buf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return esp_wifi_internal_tx(ifx, buffer, (uint16_t)len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | WEAK int esp_wifi_internal_tx(wifi_interface_t ifx, void *buffer, uint16_t len) | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  |     if (ifx == WIFI_IF_STA && s_tx_cb[0]) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  |         /* TODO: If not needed, remove arg3 */ | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  |         return s_tx_cb[0](s_channel[0], buffer, len); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  |     if (ifx == WIFI_IF_AP && s_tx_cb[1]) { | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  |         return s_tx_cb[1](s_channel[1], buffer, len); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 20:26:02 +01:00
										 |  |  | WEAK esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn) | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (ifx == WIFI_IF_STA) { | 
					
						
							| 
									
										
										
										
											2024-01-02 17:09:37 +08:00
										 |  |  |         ESP_LOGI("esp_wifi_remote", "%s: sta: %p", __func__, fn); | 
					
						
							| 
									
										
										
										
											2023-09-26 07:43:43 +02:00
										 |  |  |         s_rx_fn[0] = fn; | 
					
						
							|  |  |  |         return ESP_OK; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (ifx == WIFI_IF_AP) { | 
					
						
							|  |  |  |         s_rx_fn[1] = fn; | 
					
						
							|  |  |  |         return ESP_OK; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ESP_FAIL; | 
					
						
							|  |  |  | } |