Просмотр исходного кода

[fix] support cmux function.
[add] support private APN access point

Signed-off-by: liuxinaliang <liuxianliang@rt-thread.com>

liuxinaliang 5 лет назад
Родитель
Сommit
99a3e9a323
5 измененных файлов с 22 добавлено и 22 удалено
  1. 1 12
      class/ppp_device_air720.c
  2. 4 0
      inc/ppp_device.h
  3. 3 1
      samples/ppp_sample.c
  4. 2 2
      src/ppp_chat.c
  5. 12 7
      src/ppp_device.c

+ 1 - 12
class/ppp_device_air720.c

@@ -29,7 +29,6 @@
 
 
 #define AIR720_WARTING_TIME_BASE 2000
 #define AIR720_WARTING_TIME_BASE 2000
 
 
-#ifndef PKG_USING_CMUX
 static const struct modem_chat_data rst_mcd[] =
 static const struct modem_chat_data rst_mcd[] =
 {
 {
     {"+++",          MODEM_CHAT_RESP_NOT_NEED,        30, 1, RT_TRUE},
     {"+++",          MODEM_CHAT_RESP_NOT_NEED,        30, 1, RT_TRUE},
@@ -43,18 +42,9 @@ static const struct modem_chat_data mcd[] =
     {PPP_APN_CMD,    MODEM_CHAT_RESP_OK,              1,  5, RT_FALSE},
     {PPP_APN_CMD,    MODEM_CHAT_RESP_OK,              1,  5, RT_FALSE},
     {PPP_DAIL_CMD,   MODEM_CHAT_RESP_CONNECT,         1, 30, RT_FALSE},
     {PPP_DAIL_CMD,   MODEM_CHAT_RESP_CONNECT,         1, 30, RT_FALSE},
 };
 };
-#else
-static const struct modem_chat_data mcd[] =
-{
-    {"AT",           MODEM_CHAT_RESP_NOT_NEED,         1,  1, RT_FALSE},
-    {"ATE0",         MODEM_CHAT_RESP_NOT_NEED,         1,  1, RT_FALSE},
-    {PPP_APN_CMD,    MODEM_CHAT_RESP_NOT_NEED,         1,  1, RT_FALSE},
-    {PPP_DAIL_CMD,   MODEM_CHAT_RESP_NOT_NEED,         1,  1, RT_FALSE},
-};
-#endif
+
 static rt_err_t ppp_air720_prepare(struct ppp_device *device)
 static rt_err_t ppp_air720_prepare(struct ppp_device *device)
 {
 {
-#ifndef PKG_USING_CMUX
     if (device->power_pin >= 0)
     if (device->power_pin >= 0)
     {
     {
         rt_pin_write(device->power_pin, AIR720_POWER_OFF);
         rt_pin_write(device->power_pin, AIR720_POWER_OFF);
@@ -69,7 +59,6 @@ static rt_err_t ppp_air720_prepare(struct ppp_device *device)
         if (err)
         if (err)
             return err;
             return err;
     }
     }
-#endif
     return modem_chat(device->uart, mcd, sizeof(mcd) / sizeof(mcd[0]));
     return modem_chat(device->uart, mcd, sizeof(mcd) / sizeof(mcd[0]));
 }
 }
 
 

+ 4 - 0
inc/ppp_device.h

@@ -24,6 +24,9 @@
 #endif
 #endif
 
 
 #define PPP_DAIL_CMD         "ATD*99#"                                  /* common dailing cmd */
 #define PPP_DAIL_CMD         "ATD*99#"                                  /* common dailing cmd */
+#ifndef USING_PUBLIC_APN
+#define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\","PPP_PRIVATE_APN
+#else
 #ifdef  PPP_APN_CMCC
 #ifdef  PPP_APN_CMCC
 #define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\",\"CMNET\""            /* China Mobile Communication Company */
 #define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\",\"CMNET\""            /* China Mobile Communication Company */
 #endif
 #endif
@@ -33,6 +36,7 @@
 #ifdef  PPP_APN_CTCC
 #ifdef  PPP_APN_CTCC
 #define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\",\"CTNET\""            /* China Telecom Communication Company */
 #define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\",\"CTNET\""            /* China Telecom Communication Company */
 #endif
 #endif
+#endif
 #define PPP_CTL_GET_CSQ      1
 #define PPP_CTL_GET_CSQ      1
 #define PPP_CTL_GET_IEMI     2
 #define PPP_CTL_GET_IEMI     2
 #define PPP_CTL_GET_TYPE     3
 #define PPP_CTL_GET_TYPE     3

+ 3 - 1
samples/ppp_sample.c

@@ -39,7 +39,9 @@ int ppp_sample_start(void)
     }
     }
     return RT_EOK;
     return RT_EOK;
 }
 }
-//INIT_APP_EXPORT(ppp_sample_start);
+#ifndef PKG_USING_CMUX
+INIT_APP_EXPORT(ppp_sample_start);
+#endif
 MSH_CMD_EXPORT_ALIAS(ppp_sample_start, ppp_start, a sample of ppp device  for dailing to network);
 MSH_CMD_EXPORT_ALIAS(ppp_sample_start, ppp_start, a sample of ppp device  for dailing to network);
 
 
 /* close ppp link ,turn off modem form network */
 /* close ppp link ,turn off modem form network */

+ 2 - 2
src/ppp_chat.c

@@ -180,7 +180,7 @@ static rt_err_t modem_chat_once(rt_device_t serial, const struct modem_chat_data
                         return RT_EOK;
                         return RT_EOK;
 
 
                     LOG_W(CHAT_DATA_FMT" not matched, got: %s", CHAT_DATA_STR(data), resp2str(resp));
                     LOG_W(CHAT_DATA_FMT" not matched, got: %s", CHAT_DATA_STR(data), resp2str(resp));
-                    continue;
+                    return -RT_ERROR;
                 }
                 }
             }
             }
         }
         }
@@ -253,7 +253,7 @@ rt_err_t modem_chat(rt_device_t serial, const struct modem_chat_data *data, rt_s
     }
     }
 
 
     serial->rx_indicate = old_rx_ind;
     serial->rx_indicate = old_rx_ind;
-#ifndef PKG_USING_CMUX
+#ifdef PKG_USING_CMUX
     LOG_D("(%s) has control by cmux.", serial->parent.name);
     LOG_D("(%s) has control by cmux.", serial->parent.name);
 #else
 #else
     LOG_D("(%s) has control by ppp_device.", serial->parent.name);
     LOG_D("(%s) has control by ppp_device.", serial->parent.name);

+ 12 - 7
src/ppp_device.c

@@ -22,6 +22,13 @@
 
 
 #include <rtdbg.h>
 #include <rtdbg.h>
 
 
+#ifdef PPP_DEVICE_DEBUG
+#define PPP_THREAD_STACK_SIZE 2048
+#else
+#define PPP_THREAD_STACK_SIZE 768
+#endif
+#define PPP_THREAD_PRIORITY   9
+
 enum
 enum
 {
 {
     PPP_STATE_PREPARE,
     PPP_STATE_PREPARE,
@@ -35,9 +42,6 @@ enum
 #define PPP_RECONNECT_TIME       2500
 #define PPP_RECONNECT_TIME       2500
 #define PPP_RECV_READ_MAX        32
 #define PPP_RECV_READ_MAX        32
 
 
-#define PPP_RECEIVE_THREAD_STACK_SIZE 768
-#define PPP_RECEIVE_THREAD_PRIORITY   7
-
 
 
 #define PPP_EVENT_RX_NOTIFY 1   // serial incoming a byte
 #define PPP_EVENT_RX_NOTIFY 1   // serial incoming a byte
 #define PPP_EVENT_LOST      2   // PPP connection is lost
 #define PPP_EVENT_LOST      2   // PPP connection is lost
@@ -59,6 +63,7 @@ static struct ppp_device *_g_ppp_device = RT_NULL;
 #ifdef PPP_DEVICE_DEBUG
 #ifdef PPP_DEVICE_DEBUG
 static void ppp_debug_hexdump(const void *data, size_t len)
 static void ppp_debug_hexdump(const void *data, size_t len)
 {
 {
+    rt_uint16_t maxlen = 16;
     rt_uint32_t offset = 0;
     rt_uint32_t offset = 0;
     size_t curlen = 0, i = 0;
     size_t curlen = 0, i = 0;
     char line[16 * 4 + 3] = {0};
     char line[16 * 4 + 3] = {0};
@@ -466,8 +471,8 @@ static int ppp_recv_entry_creat(struct ppp_device *device)
     device->recv_tid = rt_thread_create("ppp_recv",
     device->recv_tid = rt_thread_create("ppp_recv",
                                         (void (*)(void *parameter))ppp_recv_entry,
                                         (void (*)(void *parameter))ppp_recv_entry,
                                         device,
                                         device,
-                                        PPP_RECEIVE_THREAD_STACK_SIZE,
-                                        PPP_RECEIVE_THREAD_PRIORITY,
+                                        PPP_THREAD_STACK_SIZE,
+                                        PPP_THREAD_PRIORITY,
                                         20);
                                         20);
     if (device->recv_tid == RT_NULL)
     if (device->recv_tid == RT_NULL)
     {
     {
@@ -581,10 +586,10 @@ static rt_err_t ppp_device_open(struct rt_device *device, rt_uint16_t oflag)
     ppp_set_usepeerdns(ppp_device->pcb, 1);
     ppp_set_usepeerdns(ppp_device->pcb, 1);
     LOG_D("ppp_set_usepeerdns has set a dns number.");
     LOG_D("ppp_set_usepeerdns has set a dns number.");
 
 
-#ifdef USING_PPP_AUTHORIZE
+#ifdef USING_PRIVATE_APN
     /* set authorize */
     /* set authorize */
  #if PAP_SUPPORT
  #if PAP_SUPPORT
-     ppp_set_auth(ppp_device->pcb , PPPAUTHTYPE_PAP, ppp_device->config.user_name, ppp_device->config.user_name);
+     ppp_set_auth(ppp_device->pcb , PPPAUTHTYPE_PAP, PRIVATE_APN_ACCOUNT, PRIVATE_APN_PASSWORD);
  #elif CHAP_SUPPORT
  #elif CHAP_SUPPORT
      ppp_set_auth(ppp_device->pcb, PPPAUTHTYPE_CHAP, ppp_device->config.user_name, ppp_device->config.user_name);
      ppp_set_auth(ppp_device->pcb, PPPAUTHTYPE_CHAP, ppp_device->config.user_name, ppp_device->config.user_name);
  #else
  #else