1/* pptp.h: packet structures and magic constants for the PPTP protocol 2 * C. Scott Ananian <cananian@alumni.princeton.edu> 3 * 4 * $Id: pptp_msg.h,v 1.3 2003/02/15 10:37:21 quozl Exp $ 5 */ 6 7#ifndef INC_PPTP_H 8#define INC_PPTP_H 9 10/* Grab definitions of int16, int32, etc. */ 11#include <sys/types.h> 12/* define "portable" htons, etc. */ 13#define hton8(x) (x) 14#define ntoh8(x) (x) 15#define hton16(x) htons(x) 16#define ntoh16(x) ntohs(x) 17#define hton32(x) htonl(x) 18#define ntoh32(x) ntohl(x) 19 20/* PPTP magic numbers: ----------------------------------------- */ 21 22#define PPTP_MAGIC 0x1A2B3C4D /* Magic cookie for PPTP datagrams */ 23#define PPTP_PORT 1723 /* PPTP TCP port number */ 24#define PPTP_PROTO 47 /* PPTP IP protocol number */ 25 26/* Control Connection Message Types: --------------------------- */ 27 28#define PPTP_MESSAGE_CONTROL 1 29#define PPTP_MESSAGE_MANAGE 2 30 31/* Control Message Types: -------------------------------------- */ 32 33/* (Control Connection Management) */ 34#define PPTP_START_CTRL_CONN_RQST 1 35#define PPTP_START_CTRL_CONN_RPLY 2 36#define PPTP_STOP_CTRL_CONN_RQST 3 37#define PPTP_STOP_CTRL_CONN_RPLY 4 38#define PPTP_ECHO_RQST 5 39#define PPTP_ECHO_RPLY 6 40 41/* (Call Management) */ 42#define PPTP_OUT_CALL_RQST 7 43#define PPTP_OUT_CALL_RPLY 8 44#define PPTP_IN_CALL_RQST 9 45#define PPTP_IN_CALL_RPLY 10 46#define PPTP_IN_CALL_CONNECT 11 47#define PPTP_CALL_CLEAR_RQST 12 48#define PPTP_CALL_CLEAR_NTFY 13 49 50/* (Error Reporting) */ 51#define PPTP_WAN_ERR_NTFY 14 52 53/* (PPP Session Control) */ 54#define PPTP_SET_LINK_INFO 15 55 56/* PPTP version information: --------------------------------------*/ 57#define PPTP_VERSION_STRING "1.00" 58#define PPTP_VERSION 0x100 59#define PPTP_FIRMWARE_STRING "0.01" 60#define PPTP_FIRMWARE_VERSION 0x001 61 62/* PPTP capabilities: ---------------------------------------------*/ 63 64/* (Framing capabilities for msg sender) */ 65#define PPTP_FRAME_ASYNC 1 66#define PPTP_FRAME_SYNC 2 67#define PPTP_FRAME_ANY 3 68 69/* (Bearer capabilities for msg sender) */ 70#define PPTP_BEARER_ANALOG 1 71#define PPTP_BEARER_DIGITAL 2 72#define PPTP_BEARER_ANY 3 73 74#define PPTP_RESULT_GENERAL_ERROR 2 75 76/* (Reasons to close a connection) */ 77#define PPTP_STOP_NONE 1 /* no good reason */ 78#define PPTP_STOP_PROTOCOL 2 /* can't support peer's protocol version */ 79#define PPTP_STOP_LOCAL_SHUTDOWN 3 /* requester is being shut down */ 80 81/* PPTP datagram structures (all data in network byte order): ----------*/ 82 83struct pptp_header { 84 u_int16_t length; /* message length in octets, including header */ 85 u_int16_t pptp_type; /* PPTP message type. 1 for control message. */ 86 u_int32_t magic; /* this should be PPTP_MAGIC. */ 87 u_int16_t ctrl_type; /* Control message type (0-15) */ 88 u_int16_t reserved0; /* reserved. MUST BE ZERO. */ 89}; 90 91struct pptp_start_ctrl_conn { /* for control message types 1 and 2 */ 92 struct pptp_header header; 93 94 u_int16_t version; /* PPTP protocol version. = PPTP_VERSION */ 95 u_int8_t result_code; /* these two fields should be zero on rqst msg*/ 96 u_int8_t error_code; /* 0 unless result_code==2 (General Error) */ 97 u_int32_t framing_cap; /* Framing capabilities */ 98 u_int32_t bearer_cap; /* Bearer Capabilities */ 99 u_int16_t max_channels; /* Maximum Channels (=0 for PNS, PAC ignores) */ 100 u_int16_t firmware_rev; /* Firmware or Software Revision */ 101 u_int8_t hostname[64]; /* Host Name (64 octets, zero terminated) */ 102 u_int8_t vendor[64]; /* Vendor string (64 octets, zero term.) */ 103 /* MS says that end of hostname/vendor fields should be filled with */ 104 /* octets of value 0, but Win95 PPTP driver doesn't do this. */ 105}; 106 107struct pptp_stop_ctrl_conn { /* for control message types 3 and 4 */ 108 struct pptp_header header; 109 110 u_int8_t reason_result; /* reason for rqst, result for rply */ 111 u_int8_t error_code; /* MUST be 0, unless rply result==2 (general err)*/ 112 u_int16_t reserved1; /* MUST be 0 */ 113}; 114 115struct pptp_echo_rqst { /* for control message type 5 */ 116 struct pptp_header header; 117 u_int32_t identifier; /* arbitrary value set by sender which is used */ 118 /* to match up reply and request */ 119}; 120 121struct pptp_echo_rply { /* for control message type 6 */ 122 struct pptp_header header; 123 u_int32_t identifier; /* should correspond to id of rqst */ 124 u_int8_t result_code; 125 u_int8_t error_code; /* =0, unless result_code==2 (general error) */ 126 u_int16_t reserved1; /* MUST BE ZERO */ 127}; 128 129struct pptp_out_call_rqst { /* for control message type 7 */ 130 struct pptp_header header; 131 u_int16_t call_id; /* Call ID (unique id used to multiplex data) */ 132 u_int16_t call_sernum; /* Call Serial Number (used for logging) */ 133 u_int32_t bps_min; /* Minimum BPS (lowest acceptable line speed) */ 134 u_int32_t bps_max; /* Maximum BPS (highest acceptable line speed) */ 135 u_int32_t bearer; /* Bearer type */ 136 u_int32_t framing; /* Framing type */ 137 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */ 138 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */ 139 u_int16_t phone_len; /* Phone Number Length (num. of valid digits) */ 140 u_int16_t reserved1; /* MUST BE ZERO */ 141 u_int8_t phone_num[64]; /* Phone Number (64 octets, null term.) */ 142 u_int8_t subaddress[64]; /* Subaddress (64 octets, null term.) */ 143}; 144 145struct pptp_out_call_rply { /* for control message type 8 */ 146 struct pptp_header header; 147 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/ 148 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/ 149 u_int8_t result_code; /* Result Code (1 is no errors) */ 150 u_int8_t error_code; /* Error Code (=0 unless result_code==2) */ 151 u_int16_t cause_code; /* Cause Code (addt'l failure information) */ 152 u_int32_t speed; /* Connect Speed (in BPS) */ 153 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */ 154 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */ 155 u_int32_t channel; /* Physical Channel ID (for logging) */ 156}; 157 158struct pptp_in_call_rqst { /* for control message type 9 */ 159 struct pptp_header header; 160 u_int16_t call_id; /* Call ID (unique id used to multiplex data) */ 161 u_int16_t call_sernum; /* Call Serial Number (used for logging) */ 162 u_int32_t bearer; /* Bearer type */ 163 u_int32_t channel; /* Physical Channel ID (for logging) */ 164 u_int16_t dialed_len; /* Dialed Number Length (# of valid digits) */ 165 u_int16_t dialing_len; /* Dialing Number Length (# of valid digits) */ 166 u_int8_t dialed_num[64]; /* Dialed Number (64 octets, zero term.) */ 167 u_int8_t dialing_num[64]; /* Dialing Number (64 octets, zero term.) */ 168 u_int8_t subaddress[64]; /* Subaddress (64 octets, zero term.) */ 169}; 170 171struct pptp_in_call_rply { /* for control message type 10 */ 172 struct pptp_header header; 173 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/ 174 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/ 175 u_int8_t result_code; /* Result Code (1 is no errors) */ 176 u_int8_t error_code; /* Error Code (=0 unless result_code==2) */ 177 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */ 178 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */ 179 u_int16_t reserved1; /* MUST BE ZERO */ 180}; 181 182struct pptp_in_call_connect { /* for control message type 11 */ 183 struct pptp_header header; 184 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/ 185 u_int16_t reserved1; /* MUST BE ZERO */ 186 u_int32_t speed; /* Connect Speed (in BPS) */ 187 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */ 188 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */ 189 u_int32_t framing; /* Framing type */ 190}; 191 192struct pptp_call_clear_rqst { /* for control message type 12 */ 193 struct pptp_header header; 194 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/ 195 u_int16_t reserved1; /* MUST BE ZERO */ 196}; 197 198struct pptp_call_clear_ntfy { /* for control message type 13 */ 199 struct pptp_header header; 200 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/ 201 u_int8_t result_code; /* Result Code */ 202 u_int8_t error_code; /* Error Code (=0 unless result_code==2) */ 203 u_int16_t cause_code; /* Cause Code (for ISDN, is Q.931 cause code) */ 204 u_int16_t reserved1; /* MUST BE ZERO */ 205 u_int8_t call_stats[128]; /* Call Statistics: 128 octets, ascii, 0-term */ 206}; 207 208struct pptp_wan_err_ntfy { /* for control message type 14 */ 209 struct pptp_header header; 210 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/ 211 u_int16_t reserved1; /* MUST BE ZERO */ 212 u_int32_t crc_errors; /* CRC errors */ 213 u_int32_t frame_errors; /* Framing errors */ 214 u_int32_t hard_errors; /* Hardware overruns */ 215 u_int32_t buff_errors; /* Buffer overruns */ 216 u_int32_t time_errors; /* Time-out errors */ 217 u_int32_t align_errors; /* Alignment errors */ 218}; 219 220struct pptp_set_link_info { /* for control message type 15 */ 221 struct pptp_header header; 222 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst) */ 223 u_int16_t reserved1; /* MUST BE ZERO */ 224 u_int32_t send_accm; /* Send ACCM (for PPP packets; default 0xFFFFFFFF)*/ 225 u_int32_t recv_accm; /* Receive ACCM (for PPP pack.;default 0xFFFFFFFF)*/ 226}; 227 228/* helpful #defines: -------------------------------------------- */ 229#define pptp_isvalid_ctrl(header, type, length) \ 230 (!( ( ntoh16(((struct pptp_header *)header)->length) < (length) ) || \ 231 ( ntoh16(((struct pptp_header *)header)->pptp_type) !=(type) ) || \ 232 ( ntoh32(((struct pptp_header *)header)->magic) !=PPTP_MAGIC) || \ 233 ( ntoh16(((struct pptp_header *)header)->ctrl_type) > PPTP_SET_LINK_INFO) || \ 234 ( ntoh16(((struct pptp_header *)header)->reserved0) !=0 ) )) 235 236#define PPTP_HEADER_CTRL(type) \ 237{ hton16(PPTP_CTRL_SIZE(type)), \ 238 hton16(PPTP_MESSAGE_CONTROL), \ 239 hton32(PPTP_MAGIC), \ 240 hton16(type), 0 } 241 242#define PPTP_CTRL_SIZE(type) ( \ 243(type==PPTP_START_CTRL_CONN_RQST)?sizeof(struct pptp_start_ctrl_conn): \ 244(type==PPTP_START_CTRL_CONN_RPLY)?sizeof(struct pptp_start_ctrl_conn): \ 245(type==PPTP_STOP_CTRL_CONN_RQST )?sizeof(struct pptp_stop_ctrl_conn): \ 246(type==PPTP_STOP_CTRL_CONN_RPLY )?sizeof(struct pptp_stop_ctrl_conn): \ 247(type==PPTP_ECHO_RQST )?sizeof(struct pptp_echo_rqst): \ 248(type==PPTP_ECHO_RPLY )?sizeof(struct pptp_echo_rply): \ 249(type==PPTP_OUT_CALL_RQST )?sizeof(struct pptp_out_call_rqst): \ 250(type==PPTP_OUT_CALL_RPLY )?sizeof(struct pptp_out_call_rply): \ 251(type==PPTP_IN_CALL_RQST )?sizeof(struct pptp_in_call_rqst): \ 252(type==PPTP_IN_CALL_RPLY )?sizeof(struct pptp_in_call_rply): \ 253(type==PPTP_IN_CALL_CONNECT )?sizeof(struct pptp_in_call_connect): \ 254(type==PPTP_CALL_CLEAR_RQST )?sizeof(struct pptp_call_clear_rqst): \ 255(type==PPTP_CALL_CLEAR_NTFY )?sizeof(struct pptp_call_clear_ntfy): \ 256(type==PPTP_WAN_ERR_NTFY )?sizeof(struct pptp_wan_err_ntfy): \ 257(type==PPTP_SET_LINK_INFO )?sizeof(struct pptp_set_link_info): \ 2580) 259#ifndef max 260#define max(a,b) (((a)>(b))?(a):(b)) 261#endif 262#define PPTP_CTRL_SIZE_MAX ( \ 263max(sizeof(struct pptp_start_ctrl_conn), \ 264max(sizeof(struct pptp_echo_rqst), \ 265max(sizeof(struct pptp_echo_rply), \ 266max(sizeof(struct pptp_out_call_rqst), \ 267max(sizeof(struct pptp_out_call_rply), \ 268max(sizeof(struct pptp_in_call_rqst), \ 269max(sizeof(struct pptp_in_call_rply), \ 270max(sizeof(struct pptp_in_call_connect), \ 271max(sizeof(struct pptp_call_clear_rqst), \ 272max(sizeof(struct pptp_call_clear_ntfy), \ 273max(sizeof(struct pptp_wan_err_ntfy), \ 274max(sizeof(struct pptp_set_link_info), 0))))))))))))) 275 276 277/* gre header structure: -------------------------------------------- */ 278 279#define PPTP_GRE_PROTO 0x880B 280#define PPTP_GRE_VER 0x1 281 282#define PPTP_GRE_FLAG_C 0x80 283#define PPTP_GRE_FLAG_R 0x40 284#define PPTP_GRE_FLAG_K 0x20 285#define PPTP_GRE_FLAG_S 0x10 286#define PPTP_GRE_FLAG_A 0x80 287 288#define PPTP_GRE_IS_C(f) ((f)&PPTP_GRE_FLAG_C) 289#define PPTP_GRE_IS_R(f) ((f)&PPTP_GRE_FLAG_R) 290#define PPTP_GRE_IS_K(f) ((f)&PPTP_GRE_FLAG_K) 291#define PPTP_GRE_IS_S(f) ((f)&PPTP_GRE_FLAG_S) 292#define PPTP_GRE_IS_A(f) ((f)&PPTP_GRE_FLAG_A) 293 294struct pptp_gre_header { 295 u_int8_t flags; /* bitfield */ 296 u_int8_t ver; /* should be PPTP_GRE_VER (enhanced GRE) */ 297 u_int16_t protocol; /* should be PPTP_GRE_PROTO (ppp-encaps) */ 298 u_int16_t payload_len; /* size of ppp payload, not inc. gre header */ 299 u_int16_t call_id; /* peer's call_id for this session */ 300 u_int32_t seq; /* sequence number. Present if S==1 */ 301 u_int32_t ack; /* seq number of highest packet recieved by */ 302 /* sender in this session */ 303}; 304 305#endif /* INC_PPTP_H */ 306