LingYun IoT Studio NB-IoT research project
Guo Wenxue
2018-11-20 bc9652bd9ad0c4ff9cf595ba68f702f44a92a3d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/********************************************************************************
 *      Copyright:  (C) guowenxue<guowenxue@gmail.com>
 *                  All rights reserved.
 *
 *       Filename:  ppp.h
 *    Description:  This head file is for PPP dial up thread.
 *
 *        Version:  1.0.0(02/17/2012~)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "02/17/2012 11:11:54 AM"
 *                 
 ********************************************************************************/
#ifndef __PPP_H
#define __PPP_H
 
#include <netinet/in.h>
 
#include "cp_comport.h"
#include "cp_proc.h"
#include "cp_gprs.h"
 
#define PPPD_DIAL_TIMEOUT             20000  /* 20 seconds */
#define PING_INTERVAL_TIME            10000  /* 10 seconds */
 
#define DEFAULT_PING_INTERVAL         30
#define APN_LEN                       128
#define UID_LEN                       64
#define PWD_LEN                       64
    
#define APN_3G                        3
#define APN_2G                        2
    
#define PPPD_DIAL_SCRIPTS             "/apps/tools/ifup-ppp"
#define PPP_INTERFACE_NAME            "ppp10"
#define PPP_PROC_NET_DEV              "/proc/net/dev"
 
#define DEF_PING_DST                  "4.2.2.2"
 
#define APN_DEF_CONF_FILE             "/apps/etc/ppp/default_apn.conf"
 
enum
{
    DISCONNECT = 0,
    SELECTED_APN,
    CONNECTING,
    CONNECTED,
};
 
 
typedef struct apn_account_s
{   
    char            apn[APN_LEN];
    char            uid[UID_LEN];    
    char            pwd[PWD_LEN];
    char            auth[10];  /*  PAP or CHAP */
} apn_account_t;  
 
typedef struct pppd_info_s
{
    char            netaddr[INET_ADDRSTRLEN];
    char            ptpaddr[INET_ADDRSTRLEN];
    unsigned long   start_time;
    unsigned long   ping_time;
    pid_t           pid;
} pppd_info_t;
 
typedef struct ppp_stat_s
{
    unsigned long long ullRx_Packets;   // total packets received 
    unsigned long long ullTx_Packets;   // total packets transmitted
    unsigned long long ullRx_Bytes; // total bytes received   
    unsigned long long ullTx_Bytes; // total bytes transmitted     
 
    unsigned long ulRx_Errors;  // bad packets received   
    unsigned long ulTx_Errors;  // packet transmit problems
    unsigned long ulRx_Dropped; // no space in linux buffers
    unsigned long ulTx_Dropped; // no space available in linux
    unsigned long ulRx_Multicast;   // multicast packets received   
    unsigned long ulRx_Compressed;
    unsigned long ulTx_Compressed;
    unsigned long ulCollisions;
 
    /* detailed rx_errors */
    unsigned long ulRx_Length_Errors;
    unsigned long ulRx_Over_Errors; // receiver ring buff overflow
    unsigned long ulRx_CRC_Errors;  // recved pkt with crc error
    unsigned long ulRx_Frame_Errors;    // recv'd frame alignment error
    unsigned long ulRx_FIFO_Errors; // recv'r fifo overrun    
    unsigned long ulRx_Missed_Errors;   // receiver missed packet  
 
    /* detailed tx_errors */
    unsigned long ulTx_Aborted_Errors;
    unsigned long ulTx_Carrier_Errors;
    unsigned long ulTx_FIFO_Errors;
    unsigned long ulTx_Heartbeat_Errors;
    unsigned long ulTx_Window_Errors;
} ppp_stat_t;
 
#define MAX_PPP_FAIL_CNT             3
 
#define PPP_STOP                     0  /* PPP not work, but signal good */
#define SIG_WEAK                     1  /* PPP not work and signal is very weak */
#define PPP_CONN                     2  /* PPP is connecting  */
#define PPP_BAD                      3  /* PPP is connected, but network/signal not good */
#define PPP_GOOD                     4  /* PPP is connected and network/signal good */
typedef struct ppp_ctx_s
{
    unsigned char      enable;       /* Enable PPP thread running or not, RFU */
    unsigned char      status;       /* Current PPP connection status */
    unsigned char      network;      /* PPP network status: PPP_FAIL,PPP_BAD,PPP_GOOD */
    char               dev[10];      /* PPP dial up device name, such as PPP10  */
 
    pthread_t          thread_id;    /* PPP Thread ID, RFU */
 
    pppd_info_t        pppd_info;    /* pppd process information */
    ppp_stat_t         ppp_stat;     /* PPP network statistic */
    unsigned char      fail_cnt;     /* PPP failure count */
 
    apn_account_t      apn;          /* PPP dial up APN */
 
    char               ping_ip[INET_ADDRSTRLEN];
    long               ping_interval;
 
    comport_t          *comport;
    modinfo_t          *module;
} ppp_ctx_t;
 
int get_apn_conf(char *ini_name, char *ini_key, apn_account_t *apn, unsigned char type);
int check_pppd_pid(char *find_key);
int check_ppp_interface(char *ppp_inf);
int start_ppp_dial_cmd(comport_t  *comport, apn_account_t *apn, char *ppp_inf);
int check_ppp_ipaddr(pppd_info_t  *pppd_info, char *ppp_inf);
int check_ppp_stat_t(ppp_stat_t  *ppp_stat, char *ppp_inf);
int stop_ppp_connect(ppp_ctx_t *ppp_ctx);
 
int start_thread_ppp(modinfo_t *module);
 
#endif /*  End of __PPP_H */