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 void start_pppd_ol2tp(int tunnel_fd, int session_fd, int tunnel_id, 74 int session_id); 75 void start_pppd_pptp(int pptp_fd); 76 77 /* Each protocol must implement everything defined in this structure. Note that 78 * timeout intervals are in milliseconds, where zero means forever. To indicate 79 * an error, one should use a negative exit code such as -REMOTE_REQUESTED. */ 80 struct protocol { 81 /* The name of this protocol. */ 82 char *name; 83 /* The number of arguments. */ 84 int arguments; 85 /* The usage of the arguments. */ 86 char *usage; 87 /* Connect to the server and return the next timeout interval. */ 88 int (*connect)(char **arguments); 89 /* Process the incoming packet and return the next timeout interval. */ 90 int (*process)(); 91 /* Handle the timeout event and return the next timeout interval. */ 92 int (*timeout)(); 93 /* Handle the shutdown event. */ 94 void (*shutdown)(); 95 }; 96 97 #endif /* __MTPD_H__ */ 98