• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __MTPD_H__
18 #define __MTPD_H__
19 
20 #if !defined(PX_PROTO_OLAC)
21 #define USING_UAPI
22 #endif
23 
24 #if defined(USING_UAPI)
25 /* This stuff isn't in uapi. */
26 #define PX_PROTO_OLAC 3
27 #define PX_PROTO_OPNS 4
28 
29 struct sockaddr_pppopns {
30  sa_family_t sa_family;
31  unsigned int sa_protocol;
32  int tcp_socket;
33  uint16_t local;
34  uint16_t remote;
35 } __attribute__((packed));
36 
37 struct sockaddr_pppolac {
38  sa_family_t sa_family;
39  unsigned int sa_protocol;
40  int udp_socket;
41  struct __attribute__((packed)) {
42    uint16_t tunnel;
43    uint16_t session;
44  } local, remote;
45 } __attribute__((packed));
46 #endif
47 
48 /* The socket to the server. */
49 extern int the_socket;
50 
51 enum exit_code {
52     SYSTEM_ERROR = 1,
53     NETWORK_ERROR = 2,
54     PROTOCOL_ERROR = 3,
55     CHALLENGE_FAILED = 4,
56     USER_REQUESTED = 5,
57     REMOTE_REQUESTED = 6,
58     PPPD_EXITED = 32,
59 };
60 
61 enum log_level {
62     DEBUG = 0,
63     INFO = 1,
64     WARNING = 2,
65     ERROR = 3,
66     FATAL = 4,
67     LOG_MAX = 4,
68 };
69 
70 void log_print(int level, char *format, ...);
71 void create_socket(int family, int type, char *server, char *port);
72 void start_pppd(int pppox);
73 
74 /* Each protocol must implement everything defined in this structure. Note that
75  * timeout intervals are in milliseconds, where zero means forever. To indicate
76  * an error, one should use a negative exit code such as -REMOTE_REQUESTED. */
77 struct protocol {
78     /* The name of this protocol. */
79     char *name;
80     /* The number of arguments. */
81     int arguments;
82     /* The usage of the arguments. */
83     char *usage;
84     /* Connect to the server and return the next timeout interval. */
85     int (*connect)(char **arguments);
86     /* Process the incoming packet and return the next timeout interval. */
87     int (*process)();
88     /* Handle the timeout event and return the next timeout interval. */
89     int (*timeout)();
90     /* Handle the shutdown event. */
91     void (*shutdown)();
92 };
93 
94 #endif /* __MTPD_H__ */
95