1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include <stdlib.h>
15 #include <string.h>
16 #include "esp_log.h"
17 #include "esp_modem.h"
18
19 /**
20 * @brief Dummy DCE to facilitate testing lwip ppp client with ppp server
21 *
22 */
23 typedef struct {
24 modem_dce_t parent; /*!< DCE parent class */
25 } null_modem_dce_t;
26
27
null_dce_set_working_mode(modem_dce_t * dce,modem_mode_t mode)28 static esp_err_t null_dce_set_working_mode(modem_dce_t *dce, modem_mode_t mode)
29 {
30 dce->mode = mode;
31 return ESP_OK;
32 }
33
null_dce_define_pdp_context(modem_dce_t * dce,uint32_t cid,const char * type,const char * apn)34 static esp_err_t null_dce_define_pdp_context(modem_dce_t *dce, uint32_t cid, const char *type, const char *apn)
35 {
36 return ESP_OK;
37 }
38
null_dce_dce_hang_up(modem_dce_t * dce)39 esp_err_t null_dce_dce_hang_up(modem_dce_t *dce)
40 {
41 return ESP_OK;
42 }
43
null_dce_deinit(modem_dce_t * dce)44 static esp_err_t null_dce_deinit(modem_dce_t *dce)
45 {
46 null_modem_dce_t *bg96_dce = __containerof(dce, null_modem_dce_t, parent);
47 if (dce->dte) {
48 dce->dte->dce = NULL;
49 }
50 free(bg96_dce);
51 return ESP_OK;
52 }
53
null_dce_init(modem_dte_t * dte)54 modem_dce_t *null_dce_init(modem_dte_t *dte)
55 {
56 if (!dte) return NULL;
57 /* malloc memory for bg96_dce object */
58 null_modem_dce_t *null_dce = calloc(1, sizeof(null_modem_dce_t));
59 if (!null_dce) return NULL;
60 /* Bind DTE with DCE */
61 null_dce->parent.dte = dte;
62 dte->dce = &(null_dce->parent);
63 /* Bind methods */
64 null_dce->parent.handle_line = NULL;
65 null_dce->parent.define_pdp_context = null_dce_define_pdp_context;
66 null_dce->parent.set_working_mode = null_dce_set_working_mode;
67 null_dce->parent.deinit = null_dce_deinit;
68 null_dce->parent.hang_up = null_dce_dce_hang_up;
69 /* Sync between DTE and DCE */
70 return &(null_dce->parent);
71 }
72