time_value );
637 | printf("-------------------------------------------\r\n");
638 | printf("Message #%d: idx=%d, from: %s, status: %s, time: %s, tz=GMT+%d, timestamp: %s\r\n",
639 | i+1, msg->idx, msg->from, msg->stat, msg->time, msg->tz, asctime(timeinfo));
640 | printf("Text: [\r\n%s\r\n]\r\n\r\n", msg->msg);
641 |
642 | // Check if SMS text contains known command
643 | if (strstr(msg->msg, "Esp32 info") == msg->msg) {
644 | char buffer[80];
645 | time_t rawtime;
646 | time(&rawtime);
647 | timeinfo = localtime( &rawtime );
648 | strftime(buffer,80,"%x %H:%M:%S", timeinfo);
649 | sprintf(buf, "Hi, %s\rMy time is now\r%s", msg->from, buffer);
650 | if (smsSend(CONFIG_GSM_SMS_NUMBER, buf) == 1) {
651 | printf("Response sent successfully\r\n");
652 | }
653 | else {
654 | printf("Response send failed\r\n");
655 | }
656 | }
657 | // Free allocated message text buffer
658 | if (msg->msg) free(msg->msg);
659 | if ((i+1) == messages.nmsg) {
660 | printf("Delete message at index %d\r\n", msg->idx);
661 | if (smsDelete(msg->idx) == 0) printf("Delete ERROR\r\n");
662 | else printf("Delete OK\r\n");
663 | }
664 | }
665 | free(messages.messages);
666 | }
667 | else printf("\r\nNo messages\r\n");
668 |
669 | // ** We can turn off GSM RF to save power
670 | gsm_RFOff();
671 | // ** We can now go back on line, or stay off line **
672 | //ppposInit();
673 |
674 | ESP_LOGI(SMS_TAG, "Waiting %d sec...", EXAMPLE_TASK_PAUSE);
675 | ESP_LOGI(SMS_TAG, "================================================================\n\n");
676 |
677 | xSemaphoreGive(http_mutex);
678 | for(int countdown = EXAMPLE_TASK_PAUSE; countdown >= 0; countdown--) {
679 | vTaskDelay(1000 / portTICK_PERIOD_MS);
680 | }
681 | }
682 | }
683 | #endif
684 |
685 |
686 | #ifdef CONFIG_GSM_USE_WIFI_AP
687 |
688 | // ==== WiFi handling & simple WebServer ====================================================
689 |
690 | // FreeRTOS event group to signal when we are connected & ready to make a request
691 | static EventGroupHandle_t wifi_event_group;
692 |
693 | // The event group allows multiple bits for each event,
694 | const int CONNECTED_BIT = BIT0;
695 | const int APSTARTED_BIT = BIT1;
696 |
697 | //-------------------------------------------------------------------
698 | esp_err_t esp32_wifi_eventHandler(void *ctx, system_event_t *event) {
699 | switch(event->event_id) {
700 | case SYSTEM_EVENT_STA_START:
701 | esp_wifi_connect();
702 | break;
703 | case SYSTEM_EVENT_STA_GOT_IP:
704 | xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
705 | break;
706 | case SYSTEM_EVENT_STA_DISCONNECTED:
707 | /* This is a workaround as ESP32 WiFi libs don't currently
708 | auto-reassociate. */
709 | esp_wifi_connect();
710 | xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
711 | break;
712 | case SYSTEM_EVENT_AP_START:
713 | xEventGroupSetBits(wifi_event_group, APSTARTED_BIT);
714 | ESP_LOGD(WEBSRV_TAG, "AP Started");
715 | break;
716 | case SYSTEM_EVENT_AP_STOP:
717 | xEventGroupClearBits(wifi_event_group, APSTARTED_BIT);
718 | ESP_LOGD(WEBSRV_TAG, "AP Stopped");
719 | break;
720 | case SYSTEM_EVENT_AP_STACONNECTED:
721 | ESP_LOGD(WEBSRV_TAG, "station connected to access point. Connected stations:");
722 | wifi_sta_list_t sta_list;
723 | ESP_ERROR_CHECK( esp_wifi_ap_get_sta_list(&sta_list));
724 | for(int i = 0; i < sta_list.num; i++) {
725 | //Print the mac address of the connected station
726 | wifi_sta_info_t sta = sta_list.sta[i];
727 | ESP_LOGD(WEBSRV_TAG, "Station %d MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", i, sta.mac[0], sta.mac[1], sta.mac[2], sta.mac[3], sta.mac[4], sta.mac[5]);
728 | }
729 | break;
730 | case SYSTEM_EVENT_AP_STADISCONNECTED:
731 | ESP_LOGD(WEBSRV_TAG, "station disconnected from access point");
732 | break;
733 | default:
734 | break;
735 | }
736 | return ESP_OK;
737 | }
738 |
739 | //----------------------------------------------------------------------------------------
740 | static void http_get_fromInternet(struct netconn *conn, const char *request, uint8_t type)
741 | {
742 | ESP_LOGD(WEBSRV_TAG, "Get data from Internet");
743 | const struct addrinfo hints = {
744 | .ai_family = AF_INET,
745 | .ai_socktype = SOCK_STREAM,
746 | };
747 | struct addrinfo *res;
748 | int s, r;
749 | char recv_buf[128];
750 | int rlen=0, totlen=0;
751 | char *buffer = NULL;
752 | char *hdr_end_ptr = NULL;
753 |
754 | // =======================================================
755 | // Other tasks may use PPPoS, wait until they are finished
756 | // =======================================================
757 | if (!(xSemaphoreTake(http_mutex, TASK_SEMAPHORE_WAIT))) {
758 | ESP_LOGE(WEBSRV_TAG, "ERROR: CANNOT GET MUTEX");
759 | return;
760 | }
761 |
762 | // ** We must be connected to Internet
763 | if (ppposInit() == 0) {
764 | ESP_LOGE(WEBSRV_TAG, "PPPoS not initialized");
765 | xSemaphoreGive(http_mutex);
766 | return;
767 | }
768 |
769 | int err = getaddrinfo(WEB_SERVER, "80", &hints, &res);
770 | if(err != 0 || res == NULL) {
771 | ESP_LOGE(WEBSRV_TAG, "DNS lookup failed err=%d res=%p", err, res);
772 | xSemaphoreGive(http_mutex);
773 | return;
774 | }
775 |
776 | // Create socket and connect to http server
777 | s = socket(res->ai_family, res->ai_socktype, 0);
778 | if (s < 0) {
779 | ESP_LOGE(WEBSRV_TAG, "... Failed to allocate socket.");
780 | freeaddrinfo(res);
781 | xSemaphoreGive(http_mutex);
782 | return;
783 | }
784 |
785 | if(connect(s, res->ai_addr, res->ai_addrlen) != 0) {
786 | ESP_LOGE(WEBSRV_TAG, "... socket connect failed errno=%d", errno);
787 | close(s);
788 | freeaddrinfo(res);
789 | xSemaphoreGive(http_mutex);
790 | return;
791 | }
792 |
793 | freeaddrinfo(res);
794 |
795 | // Send GET request
796 | if (write(s, request, strlen(request)) < 0) {
797 | ESP_LOGE(WEBSRV_TAG, "... socket send failed");
798 | close(s);
799 | xSemaphoreGive(http_mutex);
800 | return;
801 | }
802 |
803 | // Get the response to buffer
804 | buffer = malloc(2048);
805 | if (!buffer) {
806 | ESP_LOGE(WEBSRV_TAG, "ERROR allocating receive buffer");
807 | close(s);
808 | buffer = NULL;
809 | xSemaphoreGive(http_mutex);
810 | return;
811 | }
812 | memset(buffer, 0, 2048);
813 | /* Read HTTP response */
814 | int opt = 500;
815 | int first_block = 1;
816 | char *cont_len = NULL;
817 | int clen = 0;
818 | rlen = 0;
819 | totlen = 0;
820 | do {
821 | bzero(recv_buf, sizeof(recv_buf));
822 | r = read(s, recv_buf, sizeof(recv_buf)-1);
823 | totlen += r;
824 | if ((rlen + r) < 2048) {
825 | memcpy(buffer+rlen, recv_buf, r);
826 | rlen += r;
827 | buffer[rlen] = '\0';
828 | if (clen == 0) {
829 | cont_len = strstr(buffer, "Content-Length: ");
830 | if (cont_len) {
831 | cont_len += 16;
832 | if (strstr(cont_len, "\r\n")) {
833 | char slen[16] = {0};
834 | memcpy(slen, cont_len, strstr(cont_len, "\r\n")-cont_len);
835 | clen = atoi(slen);
836 | }
837 | }
838 | }
839 | if (hdr_end_ptr == NULL) {
840 | hdr_end_ptr = strstr(buffer, "\r\n\r\n");
841 | if (hdr_end_ptr) hdr_end_ptr += 4;
842 | }
843 | else if (clen > 0) {
844 | if (strlen(hdr_end_ptr) >= clen) break;
845 | }
846 | }
847 | if (first_block) {
848 | lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(int));
849 | first_block = 0;
850 | }
851 | } while(r > 0);
852 |
853 | close(s);
854 | xSemaphoreGive(http_mutex);
855 |
856 | // Send the response to the client connected via WiFi AP
857 | if (hdr_end_ptr) {
858 | ESP_LOGI(WEBSRV_TAG, "Received data: rlen=%d, total=%d, body=%d [%d]", rlen, totlen, strlen(hdr_end_ptr), clen);
859 | }
860 | else {
861 | ESP_LOGE(WEBSRV_TAG, "No header end found, rlen=%d", rlen);
862 | free(buffer);
863 | buffer = NULL;
864 | return;
865 | }
866 |
867 | if (type) netconn_write(conn, "Received via PPPoS:
\r\n", 39, NETCONN_NOCOPY);
868 | netconn_write(conn, hdr_end_ptr, strlen(hdr_end_ptr), NETCONN_NOCOPY);
869 | if (type) netconn_write(conn, "
\r\n", 13, NETCONN_NOCOPY);
870 | free(buffer);
871 | buffer = NULL;
872 |
873 | return;
874 | }
875 |
876 |
877 | //-----------------------------------------------------------
878 | static void http_server_netconn_serve(struct netconn *conn) {
879 |
880 | struct netbuf *inbuf;
881 | char *buf;
882 | u16_t buflen;
883 | err_t err;
884 |
885 | err = netconn_recv(conn, &inbuf);
886 |
887 | if (err == ERR_OK) {
888 |
889 | netbuf_data(inbuf, (void**)&buf, &buflen);
890 |
891 | // extract the first line, with the request
892 | char *first_line = strtok(buf, "\n");
893 |
894 | if (first_line) {
895 | // default page
896 | if (strstr(first_line, "GET / ")) {
897 | netconn_write(conn, http_html_hdr, sizeof(http_html_hdr) - 1, NETCONN_NOCOPY);
898 | netconn_write(conn, http_index_html, sizeof(http_index_html) - 1, NETCONN_NOCOPY);
899 | http_get_fromInternet(conn, REQUEST, 1);
900 | netconn_write(conn, "\n\n", 16, NETCONN_NOCOPY);
901 | ESP_LOGI(WEBSRV_TAG, "Got request from client");
902 | }
903 | else if (strstr(first_line, "GET /test ")) {
904 | http_get_fromInternet(conn, REQUEST1, 0);
905 | ESP_LOGI(WEBSRV_TAG, "Got [test] request from client");
906 | }
907 | else {
908 | ESP_LOGW(WEBSRV_TAG, "Unknown request type [%s]", first_line);
909 | }
910 | }
911 | else {
912 | ESP_LOGE(WEBSRV_TAG, "Unknown request");
913 | }
914 | }
915 |
916 | // close the connection and free the buffer
917 | netconn_close(conn);
918 | netbuf_delete(inbuf);
919 | }
920 |
921 | //-------------------------------------------
922 | static void http_server(void *pvParameters) {
923 |
924 | struct netconn *conn, *newconn;
925 | err_t err;
926 | conn = netconn_new(NETCONN_TCP);
927 | netconn_bind(conn, NULL, 80);
928 | netconn_listen(conn);
929 | ESP_LOGD(WEBSRV_TAG, "HTTP Server listening...");
930 | do {
931 | err = netconn_accept(conn, &newconn);
932 | ESP_LOGD(WEBSRV_TAG, "New client connected");
933 | if (err == ERR_OK) {
934 | http_server_netconn_serve(newconn);
935 | netconn_delete(newconn);
936 | }
937 | } while(err == ERR_OK);
938 | netconn_close(conn);
939 | netconn_delete(conn);
940 | ESP_LOGE(WEBSRV_TAG, "Netconn accept error, task halted!");
941 | }
942 |
943 | // ==========================================================================================
944 |
945 | #endif
946 |
947 |
948 | //=============
949 | void app_main()
950 | {
951 | http_mutex = xSemaphoreCreateMutex();
952 |
953 | #ifdef CONFIG_GSM_USE_WIFI_AP
954 | // ----- Set AP(STA)---------------------------------------------------
955 | nvs_flash_init();
956 | tcpip_adapter_init();
957 | wifi_event_group = xEventGroupCreate();
958 | ESP_ERROR_CHECK( esp_event_loop_init(esp32_wifi_eventHandler, NULL) );
959 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
960 | ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
961 | ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
962 | ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
963 | wifi_config_t apConfig = {
964 | .ap = {
965 | .ssid="ESP32_TESTAP",
966 | .ssid_len=0,
967 | .password="",
968 | .channel=0,
969 | .authmode=WIFI_AUTH_OPEN,
970 | .ssid_hidden=0,
971 | .max_connection=8,
972 | .beacon_interval=100
973 | },
974 | };
975 | ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &apConfig) );
976 |
977 | //wifi_config_t staConfig = {
978 | // .sta = {
979 | // .ssid = "MySSID",
980 | // .password = "MyPassword",
981 | // }
982 | //};
983 | //ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &staConfig) );
984 |
985 | ESP_ERROR_CHECK( esp_wifi_start() );
986 | // ---------------------------------------------------------------------
987 |
988 | xEventGroupWaitBits(wifi_event_group, APSTARTED_BIT, pdFALSE, pdTRUE, portMAX_DELAY);
989 | // start the HTTP Server task
990 | xTaskCreate(&http_server, "http_server", 2048, NULL, 5, NULL);
991 |
992 | vTaskDelay(1000 / portTICK_RATE_MS);
993 | #endif
994 |
995 | if (ppposInit() == 0) {
996 | ESP_LOGE("PPPoS EXAMPLE", "ERROR: GSM not initialized, HALTED");
997 | while (1) {
998 | vTaskDelay(1000 / portTICK_RATE_MS);
999 | }
1000 | }
1001 |
1002 | // ==== Get time from NTP server =====
1003 | time_t now = 0;
1004 | struct tm timeinfo = { 0 };
1005 | int retry = 0;
1006 | const int retry_count = 10;
1007 |
1008 | time(&now);
1009 | localtime_r(&now, &timeinfo);
1010 |
1011 | while (1) {
1012 | printf("\r\n");
1013 | ESP_LOGI(TIME_TAG,"OBTAINING TIME");
1014 | ESP_LOGI(TIME_TAG, "Initializing SNTP");
1015 | sntp_setoperatingmode(SNTP_OPMODE_POLL);
1016 | sntp_setservername(0, "pool.ntp.org");
1017 | sntp_init();
1018 | ESP_LOGI(TIME_TAG,"SNTP INITIALIZED");
1019 |
1020 | // wait for time to be set
1021 | now = 0;
1022 | while ((timeinfo.tm_year < (2016 - 1900)) && (++retry < retry_count)) {
1023 | ESP_LOGI(TIME_TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
1024 | vTaskDelay(2000 / portTICK_PERIOD_MS);
1025 | time(&now);
1026 | localtime_r(&now, &timeinfo);
1027 | if (ppposStatus() != GSM_STATE_CONNECTED) break;
1028 | }
1029 | if (ppposStatus() != GSM_STATE_CONNECTED) {
1030 | sntp_stop();
1031 | ESP_LOGE(TIME_TAG, "Disconnected, waiting for reconnect");
1032 | retry = 0;
1033 | while (ppposStatus() != GSM_STATE_CONNECTED) {
1034 | vTaskDelay(100 / portTICK_RATE_MS);
1035 | }
1036 | continue;
1037 | }
1038 |
1039 | if (retry < retry_count) {
1040 | ESP_LOGI(TIME_TAG, "TIME SET TO %s", asctime(&timeinfo));
1041 | break;
1042 | }
1043 | else {
1044 | ESP_LOGI(TIME_TAG, "ERROR OBTAINING TIME\n");
1045 | }
1046 | sntp_stop();
1047 | break;
1048 | }
1049 |
1050 | // ==== Create PPPoS tasks ====
1051 | xTaskCreate(&http_get_task, "http_get_task", 4096, NULL, 5, NULL);
1052 | xTaskCreate(&https_get_task, "https_get_task", 16384, NULL, 4, NULL);
1053 | #ifdef CONFIG_GSM_SEND_SMS
1054 | // ==== Create SMS task ====
1055 | xTaskCreate(&sms_task, "sms_task", 4096, NULL, 3, NULL);
1056 | #endif
1057 |
1058 | while(1)
1059 | {
1060 | vTaskDelay(1000 / portTICK_RATE_MS);
1061 | }
1062 | }
1063 |
--------------------------------------------------------------------------------
/main/server_root_cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
3 | MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
4 | DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
5 | SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT
6 | GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC
7 | AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF
8 | q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8
9 | SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0
10 | Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA
11 | a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
12 | /PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
13 | AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
14 | CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
15 | bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
16 | c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
17 | VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
18 | ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
19 | MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
20 | Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
21 | AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
22 | uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
23 | wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
24 | X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
25 | PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
26 | KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
27 | -----END CERTIFICATE-----
28 |
--------------------------------------------------------------------------------
/pppapi.c.patch:
--------------------------------------------------------------------------------
1 | --- pppapi.c 2017-10-11 14:36:42.000000000 +0200
2 | +++ pppapi.c.patched 2017-10-11 14:39:14.000000000 +0200
3 | @@ -48,9 +48,9 @@
4 | static err_t
5 | pppapi_do_ppp_set_default(struct tcpip_api_call *m)
6 | {
7 | - struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
8 | + struct pppapi_msg *msg = (struct pppapi_msg *)m;
9 |
10 | - ppp_set_default(msg->ppp);
11 | + ppp_set_default(msg->msg.ppp);
12 | return ERR_OK;
13 | }
14 |
15 | @@ -103,8 +103,8 @@
16 | static err_t
17 | pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call *m)
18 | {
19 | - struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
20 | - ppp_set_notify_phase_callback(msg->ppp, msg->msg.setnotifyphasecb.notify_phase_cb);
21 | + struct pppapi_msg *msg = (struct pppapi_msg *)m;
22 | + ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb);
23 | return ERR_OK;
24 | }
25 |
26 | @@ -164,11 +164,11 @@
27 | static err_t
28 | pppapi_do_pppoe_create(struct tcpip_api_call *m)
29 | {
30 | - struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
31 | + struct pppapi_msg *msg = (struct pppapi_msg *)m;
32 |
33 | - msg->ppp = pppoe_create(msg->msg.ethernetcreate.pppif, msg->msg.ethernetcreate.ethif,
34 | - msg->msg.ethernetcreate.service_name, msg->msg.ethernetcreate.concentrator_name,
35 | - msg->msg.ethernetcreate.link_status_cb, msg->msg.ethernetcreate.ctx_cb);
36 | + msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif,
37 | + msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name,
38 | + msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb);
39 | return ERR_OK;
40 | }
41 |
42 | @@ -201,17 +201,17 @@
43 | static err_t
44 | pppapi_do_pppol2tp_create(struct tcpip_api_call *m)
45 | {
46 | - struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
47 | + struct pppapi_msg *msg = (struct pppapi_msg *)m;
48 |
49 | - msg->ppp = pppol2tp_create(msg->msg.l2tpcreate.pppif,
50 | - msg->msg.l2tpcreate.netif, msg->msg.l2tpcreate.ipaddr, msg->msg.l2tpcreate.port,
51 | + msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif,
52 | + msg->msg.msg.l2tpcreate.netif, msg->msg.msg.l2tpcreate.ipaddr, msg->msg.msg.l2tpcreate.port,
53 | #if PPPOL2TP_AUTH_SUPPORT
54 | - msg->msg.l2tpcreate.secret,
55 | - msg->msg.l2tpcreate.secret_len,
56 | + msg->msg.msg.l2tpcreate.secret,
57 | + msg->msg.msg.l2tpcreate.secret_len,
58 | #else /* PPPOL2TP_AUTH_SUPPORT */
59 | NULL,
60 | #endif /* PPPOL2TP_AUTH_SUPPORT */
61 | - msg->msg.l2tpcreate.link_status_cb, msg->msg.l2tpcreate.ctx_cb);
62 | + msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb);
63 | return ERR_OK;
64 | }
65 |
66 | @@ -325,9 +325,9 @@
67 | static err_t
68 | pppapi_do_ppp_free(struct tcpip_api_call *m)
69 | {
70 | - struct pppapi_msg_msg *msg = (struct pppapi_msg_msg *)m;
71 | + struct pppapi_msg *msg = (struct pppapi_msg *)m;
72 |
73 | - return ppp_free(msg->ppp);
74 | + return ppp_free(msg->msg.ppp);
75 | }
76 |
77 | /**
78 |
--------------------------------------------------------------------------------
/pppapi.c.patched:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Point To Point Protocol Sequential API module
4 | *
5 | */
6 |
7 | /*
8 | * Redistribution and use in source and binary forms, with or without modification,
9 | * are permitted provided that the following conditions are met:
10 | *
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. The name of the author may not be used to endorse or promote products
17 | * derived from this software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28 | * OF SUCH DAMAGE.
29 | *
30 | * This file is part of the lwIP TCP/IP stack.
31 | *
32 | */
33 |
34 | #include "lwip/opt.h"
35 |
36 | #if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
37 |
38 | #include "lwip/pppapi.h"
39 | #include "lwip/priv/tcpip_priv.h"
40 | #include "netif/ppp/pppoe.h"
41 | #include "netif/ppp/pppol2tp.h"
42 | #include "netif/ppp/pppos.h"
43 |
44 |
45 | /**
46 | * Call ppp_set_default() inside the tcpip_thread context.
47 | */
48 | static err_t
49 | pppapi_do_ppp_set_default(struct tcpip_api_call *m)
50 | {
51 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
52 |
53 | ppp_set_default(msg->msg.ppp);
54 | return ERR_OK;
55 | }
56 |
57 | /**
58 | * Call ppp_set_default() in a thread-safe way by running that function inside the
59 | * tcpip_thread context.
60 | */
61 | void
62 | pppapi_set_default(ppp_pcb *pcb)
63 | {
64 | struct pppapi_msg msg;
65 | msg.msg.ppp = pcb;
66 | tcpip_api_call(pppapi_do_ppp_set_default, &msg.call);
67 | }
68 |
69 |
70 | /**
71 | * Call ppp_set_auth() inside the tcpip_thread context.
72 | */
73 | static err_t
74 | pppapi_do_ppp_set_auth(struct tcpip_api_call *m)
75 | {
76 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
77 |
78 | ppp_set_auth(msg->msg.ppp, msg->msg.msg.setauth.authtype,
79 | msg->msg.msg.setauth.user, msg->msg.msg.setauth.passwd);
80 | return ERR_OK;
81 | }
82 |
83 | /**
84 | * Call ppp_set_auth() in a thread-safe way by running that function inside the
85 | * tcpip_thread context.
86 | */
87 | void
88 | pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd)
89 | {
90 | struct pppapi_msg msg;
91 | msg.msg.ppp = pcb;
92 | msg.msg.msg.setauth.authtype = authtype;
93 | msg.msg.msg.setauth.user = user;
94 | msg.msg.msg.setauth.passwd = passwd;
95 | tcpip_api_call(pppapi_do_ppp_set_auth, &msg.call);
96 | }
97 |
98 |
99 | #if PPP_NOTIFY_PHASE
100 | /**
101 | * Call ppp_set_notify_phase_callback() inside the tcpip_thread context.
102 | */
103 | static err_t
104 | pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call *m)
105 | {
106 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
107 | ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb);
108 | return ERR_OK;
109 | }
110 |
111 | /**
112 | * Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the
113 | * tcpip_thread context.
114 | */
115 | void
116 | pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb)
117 | {
118 | struct pppapi_msg msg;
119 | msg.function = pppapi_do_ppp_set_notify_phase_callback;
120 | msg.msg.ppp = pcb;
121 | msg.msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
122 | tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &msg.call);
123 | }
124 | #endif /* PPP_NOTIFY_PHASE */
125 |
126 |
127 | #if PPPOS_SUPPORT
128 | /**
129 | * Call pppos_create() inside the tcpip_thread context.
130 | */
131 | static err_t
132 | pppapi_do_pppos_create(struct tcpip_api_call *m)
133 | {
134 | struct pppapi_msg *msg = (struct pppapi_msg *)(m);
135 |
136 | msg->msg.ppp = pppos_create(msg->msg.msg.serialcreate.pppif, msg->msg.msg.serialcreate.output_cb,
137 | msg->msg.msg.serialcreate.link_status_cb, msg->msg.msg.serialcreate.ctx_cb);
138 | return ERR_OK;
139 | }
140 |
141 | /**
142 | * Call pppos_create() in a thread-safe way by running that function inside the
143 | * tcpip_thread context.
144 | */
145 | ppp_pcb*
146 | pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
147 | ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
148 | {
149 | struct pppapi_msg msg;
150 | msg.msg.msg.serialcreate.pppif = pppif;
151 | msg.msg.msg.serialcreate.output_cb = output_cb;
152 | msg.msg.msg.serialcreate.link_status_cb = link_status_cb;
153 | msg.msg.msg.serialcreate.ctx_cb = ctx_cb;
154 | tcpip_api_call(pppapi_do_pppos_create, &msg.call);
155 | return msg.msg.ppp;
156 | }
157 | #endif /* PPPOS_SUPPORT */
158 |
159 |
160 | #if PPPOE_SUPPORT
161 | /**
162 | * Call pppoe_create() inside the tcpip_thread context.
163 | */
164 | static err_t
165 | pppapi_do_pppoe_create(struct tcpip_api_call *m)
166 | {
167 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
168 |
169 | msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif,
170 | msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name,
171 | msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb);
172 | return ERR_OK;
173 | }
174 |
175 | /**
176 | * Call pppoe_create() in a thread-safe way by running that function inside the
177 | * tcpip_thread context.
178 | */
179 | ppp_pcb*
180 | pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name,
181 | const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
182 | void *ctx_cb)
183 | {
184 | struct pppapi_msg msg;
185 | msg.msg.msg.ethernetcreate.pppif = pppif;
186 | msg.msg.msg.ethernetcreate.ethif = ethif;
187 | msg.msg.msg.ethernetcreate.service_name = service_name;
188 | msg.msg.msg.ethernetcreate.concentrator_name = concentrator_name;
189 | msg.msg.msg.ethernetcreate.link_status_cb = link_status_cb;
190 | msg.msg.msg.ethernetcreate.ctx_cb = ctx_cb;
191 | tcpip_api_call(pppapi_do_pppoe_create, &msg.call);
192 | return msg.msg.ppp;
193 | }
194 | #endif /* PPPOE_SUPPORT */
195 |
196 |
197 | #if PPPOL2TP_SUPPORT
198 | /**
199 | * Call pppol2tp_create() inside the tcpip_thread context.
200 | */
201 | static err_t
202 | pppapi_do_pppol2tp_create(struct tcpip_api_call *m)
203 | {
204 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
205 |
206 | msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif,
207 | msg->msg.msg.l2tpcreate.netif, msg->msg.msg.l2tpcreate.ipaddr, msg->msg.msg.l2tpcreate.port,
208 | #if PPPOL2TP_AUTH_SUPPORT
209 | msg->msg.msg.l2tpcreate.secret,
210 | msg->msg.msg.l2tpcreate.secret_len,
211 | #else /* PPPOL2TP_AUTH_SUPPORT */
212 | NULL,
213 | #endif /* PPPOL2TP_AUTH_SUPPORT */
214 | msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb);
215 | return ERR_OK;
216 | }
217 |
218 | /**
219 | * Call pppol2tp_create() in a thread-safe way by running that function inside the
220 | * tcpip_thread context.
221 | */
222 | ppp_pcb*
223 | pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
224 | const u8_t *secret, u8_t secret_len,
225 | ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
226 | {
227 | struct pppapi_msg msg;
228 | msg.msg.msg.l2tpcreate.pppif = pppif;
229 | msg.msg.msg.l2tpcreate.netif = netif;
230 | msg.msg.msg.l2tpcreate.ipaddr = ipaddr;
231 | msg.msg.msg.l2tpcreate.port = port;
232 | #if PPPOL2TP_AUTH_SUPPORT
233 | msg.msg.msg.l2tpcreate.secret = secret;
234 | msg.msg.msg.l2tpcreate.secret_len = secret_len;
235 | #endif /* PPPOL2TP_AUTH_SUPPORT */
236 | msg.msg.msg.l2tpcreate.link_status_cb = link_status_cb;
237 | msg.msg.msg.l2tpcreate.ctx_cb = ctx_cb;
238 | tcpip_api_call(pppapi_do_pppol2tp_create, &msg.call);
239 | return msg.msg.ppp;
240 | }
241 | #endif /* PPPOL2TP_SUPPORT */
242 |
243 |
244 | /**
245 | * Call ppp_connect() inside the tcpip_thread context.
246 | */
247 | static err_t
248 | pppapi_do_ppp_connect(struct tcpip_api_call *m)
249 | {
250 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
251 |
252 | return ppp_connect(msg->msg.ppp, msg->msg.msg.connect.holdoff);
253 | }
254 |
255 | /**
256 | * Call ppp_connect() in a thread-safe way by running that function inside the
257 | * tcpip_thread context.
258 | */
259 | err_t
260 | pppapi_connect(ppp_pcb *pcb, u16_t holdoff)
261 | {
262 | struct pppapi_msg msg;
263 | msg.msg.ppp = pcb;
264 | msg.msg.msg.connect.holdoff = holdoff;
265 | return tcpip_api_call(pppapi_do_ppp_connect, &msg.call);
266 | }
267 |
268 |
269 | #if PPP_SERVER
270 | /**
271 | * Call ppp_listen() inside the tcpip_thread context.
272 | */
273 | static void
274 | pppapi_do_ppp_listen(struct pppapi_msg_msg *msg)
275 | {
276 | msg->err = ppp_listen(msg->ppp, msg->msg.listen.addrs);
277 | TCPIP_PPPAPI_ACK(msg);
278 | }
279 |
280 | /**
281 | * Call ppp_listen() in a thread-safe way by running that function inside the
282 | * tcpip_thread context.
283 | */
284 | err_t
285 | pppapi_listen(ppp_pcb *pcb, struct ppp_addrs *addrs)
286 | {
287 | struct pppapi_msg msg;
288 | msg.function = pppapi_do_ppp_listen;
289 | msg.msg.ppp = pcb;
290 | msg.msg.msg.listen.addrs = addrs;
291 | TCPIP_PPPAPI(&msg);
292 | return msg.msg.err;
293 | }
294 | #endif /* PPP_SERVER */
295 |
296 |
297 | /**
298 | * Call ppp_close() inside the tcpip_thread context.
299 | */
300 | static err_t
301 | pppapi_do_ppp_close(struct tcpip_api_call *m)
302 | {
303 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
304 |
305 | return ppp_close(msg->msg.ppp, msg->msg.msg.close.nocarrier);
306 | }
307 |
308 | /**
309 | * Call ppp_close() in a thread-safe way by running that function inside the
310 | * tcpip_thread context.
311 | */
312 | err_t
313 | pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
314 | {
315 | struct pppapi_msg msg;
316 | msg.msg.ppp = pcb;
317 | msg.msg.msg.close.nocarrier = nocarrier;
318 | return tcpip_api_call(pppapi_do_ppp_close, &msg.call);
319 | }
320 |
321 |
322 | /**
323 | * Call ppp_free() inside the tcpip_thread context.
324 | */
325 | static err_t
326 | pppapi_do_ppp_free(struct tcpip_api_call *m)
327 | {
328 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
329 |
330 | return ppp_free(msg->msg.ppp);
331 | }
332 |
333 | /**
334 | * Call ppp_free() in a thread-safe way by running that function inside the
335 | * tcpip_thread context.
336 | */
337 | err_t
338 | pppapi_free(ppp_pcb *pcb)
339 | {
340 | struct pppapi_msg msg;
341 | msg.msg.ppp = pcb;
342 | return tcpip_api_call(pppapi_do_ppp_free, &msg.call);
343 | }
344 |
345 |
346 | /**
347 | * Call ppp_ioctl() inside the tcpip_thread context.
348 | */
349 | static err_t
350 | pppapi_do_ppp_ioctl(struct tcpip_api_call *m)
351 | {
352 | struct pppapi_msg *msg = (struct pppapi_msg *)m;
353 |
354 | return ppp_ioctl(msg->msg.ppp, msg->msg.msg.ioctl.cmd, msg->msg.msg.ioctl.arg);
355 | }
356 |
357 | /**
358 | * Call ppp_ioctl() in a thread-safe way by running that function inside the
359 | * tcpip_thread context.
360 | */
361 | err_t
362 | pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
363 | {
364 | struct pppapi_msg msg;
365 | msg.msg.ppp = pcb;
366 | msg.msg.msg.ioctl.cmd = cmd;
367 | msg.msg.msg.ioctl.arg = arg;
368 | return tcpip_api_call(pppapi_do_ppp_ioctl, &msg.call);
369 | }
370 |
371 | #endif /* LWIP_PPP_API */
372 |
--------------------------------------------------------------------------------
/sdkconfig.defaults:
--------------------------------------------------------------------------------
1 | # Override some defaults to enable PPP
2 | CONFIG_PPP_SUPPORT=y
3 | CONFIG_PPP_PAP_SUPPORT=y
4 | CONFIG_PPP_DEBUG_ON=n
5 | CONFIG_TCPIP_TASK_STACK_SIZE=4096
6 | CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
7 | CONFIG_FREERTOS_HZ=1000
8 | CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
9 | CONFIG_ESPTOOLPY_AFTER_NORESET=y
10 |
--------------------------------------------------------------------------------