null_dce.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @brief Dummy DCE to facilitate testing lwip ppp client with ppp server
  20. *
  21. */
  22. typedef struct {
  23. modem_dce_t parent; /*!< DCE parent class */
  24. } null_modem_dce_t;
  25. static esp_err_t null_dce_set_working_mode(modem_dce_t *dce, modem_mode_t mode)
  26. {
  27. dce->mode = mode;
  28. return ESP_OK;
  29. }
  30. static esp_err_t null_dce_define_pdp_context(modem_dce_t *dce, uint32_t cid, const char *type, const char *apn)
  31. {
  32. return ESP_OK;
  33. }
  34. esp_err_t null_dce_dce_hang_up(modem_dce_t *dce)
  35. {
  36. return ESP_OK;
  37. }
  38. static esp_err_t null_dce_deinit(modem_dce_t *dce)
  39. {
  40. null_modem_dce_t *bg96_dce = __containerof(dce, null_modem_dce_t, parent);
  41. if (dce->dte) {
  42. dce->dte->dce = NULL;
  43. }
  44. free(bg96_dce);
  45. return ESP_OK;
  46. }
  47. modem_dce_t *null_dce_init(modem_dte_t *dte)
  48. {
  49. if (!dte) return NULL;
  50. /* malloc memory for bg96_dce object */
  51. null_modem_dce_t *null_dce = calloc(1, sizeof(null_modem_dce_t));
  52. if (!null_dce) return NULL;
  53. /* Bind DTE with DCE */
  54. null_dce->parent.dte = dte;
  55. dte->dce = &(null_dce->parent);
  56. /* Bind methods */
  57. null_dce->parent.handle_line = NULL;
  58. null_dce->parent.define_pdp_context = null_dce_define_pdp_context;
  59. null_dce->parent.set_working_mode = null_dce_set_working_mode;
  60. null_dce->parent.deinit = null_dce_deinit;
  61. null_dce->parent.hang_up = null_dce_dce_hang_up;
  62. /* Sync between DTE and DCE */
  63. return &(null_dce->parent);
  64. }