M7350v7_en_gpl

This commit is contained in:
T
2024-09-09 08:59:52 +00:00
parent f75098198c
commit 46ba6f09ec
1372 changed files with 1231198 additions and 1184 deletions

View File

@ -0,0 +1,41 @@
#include "1x_types.h"
struct Auth_Pae_tag;
struct Global_Params_tag;
#define LIB1X_ACCT_REASON_USER_REQUEST 1
#define LIB1X_ACCT_REASON_LOST_CARRIER 2
#define LIB1X_ACCT_REASON_LOST_SERVICE 3
#define LIB1X_ACCT_REASON_IDLE_TIMEOUT 4
#define LIB1X_ACCT_REASON_SESSION_TIMEOUT 5
#define LIB1X_ACCT_REASON_ADMIN_RESET 6
#define LIB1X_ACCT_REASON_ADMIN_REBOOT 7
typedef struct ACCT_SM_tag
{
int terminate_cause;
int status;
u_long elapsedSessionTime;
u_long sessionId;
int serverTimeout;
int maxReq;
int reqCount;
int aWhile;
BOOLEAN waitRespond;
unsigned long tx_packets; // == transmited packets
unsigned long rx_packets; // == received packets
unsigned long tx_bytes; // == transmited bytes
unsigned long rx_bytes; // == received bytes
} Acct_SM;
void lib1x_acctsm( Global_Params * global);
void lib1x_acctsm_init(Acct_SM * acct_sm, int maxReq, int aWhile);
BOOLEAN lib1x_acctsm_request( struct Global_Params_tag * global, int iAction, int iTerminateCause);
int lib1x_acct_request( struct Auth_Pae_tag * auth_pae, unsigned int msg_type, int iTerminateCause);
void lib1x_acct_UCS4_TO_UTF8(u_long ud, u_char * pucUTF8, u_long * ulUTF8Len);
void lib1x_acct_MAC_TO_DASH_ASCII(u_char * pucInput, u_long ulInput, u_char * pucOutput, u_long * ulOutputLen);
u_long lib1x_acct_maperr_wlan2acct(u_long ulReason);
int lib1x_acctsm_sendReqToServer( Global_Params * global);

View File

@ -0,0 +1,270 @@
#ifndef LIB1x_AUTH_PAE_H
#define LIB1x_AUTH_PAE_H
#include "1x_types.h"
#include "1x_common.h"
#include "1x_ethernet.h"
#include "1x_reauth_sm.h"
#include "1x_bauth_sm.h"
#include "1x_cdsm.h"
#include "1x_krc_sm.h"
#include "1x_kxsm.h"
#include "1x_ptsm.h"
#include "1x_acct_sm.h"
//#include "1x_radius.h"
#include <stdio.h>
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : auth_pae.h
// Programmer : Arunesh Mishra
//
// Contains declarations for Authenticator PAE
// state machine.
// Refer 8.5.4.1 page 53 in the IEEE 802.1x spec.
//
//
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//
//--------------------------------------------------
#define LIB1X_AP_QUIET_PERIOD 60 // seconds
//#define LIB1X_AP_REAUTHMAX 20 // attempts
#define LIB1X_AP_REAUTHMAX 3
#define LIB1X_AP_NAKMAX 4 // received times
//#define LIB1X_AP_TXPERIOD 30 // seconds
#define LIB1X_AP_TXPERIOD 5 // seconds
#define LIB1X_AP_SENDBUFLEN 1600
#define LIB1X_ACCTING_SENDBUFLEN 1600
#define MAX_EAP_BUFFER 10
// The reauthentication period
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
struct pktbuf
{
u_char * pkt;
u_short length; // -1 indicates no packet is stored in this slot
u_char eap_code;
u_char eap_id;
u_char eaprr_type; // = 255 if not valid i.e. the EAP packet is not a request/response pkt
};
struct Global_Params_tag;
struct Auth_Pae_tag
{
// The machine state
AUTH_PAE_STATE state;
// The Variables.
BOOLEAN eapLogoff;
BOOLEAN eapStart;
PORT_MODE_TYPE portMode;
int reAuthCount;
int nakCount;
BOOLEAN rxRespId;
BOOLEAN isSuppPresent; // true if we have a supp to communicate with
// The constants
int quietPeriod;
int reAuthMax;
int txPeriod;
// A listing of the other state machines we are going to use.
// TODO something about the port timers machine.
PT_SM * port_timers;
// Reauthentication Timer State Machine
Reauth_SM * reauth_sm;
// Backend Authentication State Machine
Bauth_SM * bauth_sm;
// Controlled Directions State Machine
CtrlDirSM * ctrl_sm;
// Key Receive State Machine
Krc_SM * krc_sm;
// Authenticator Key Transmit State Machine
Auth_KeyxmitSM * keyxmit_sm;
// Accouting State Machine
Acct_SM * acct_sm;
u_char * sendBuffer;
int sendbuflen;
u_char * acct_sendBuffer;
int acct_sendbuflen;
BOOLEAN sendreplyready; /* signals that the reply is ready for authentication message*/
BOOLEAN sendhandshakeready; /* signals that the reply is ready for key management message */
struct lib1x_eap * send_eapptr; /* used to communicate the start of eap pkt in sendbuf */
//u_char oursvr_addr[ETHER_ADDRLEN]; // ethernet address of the server interface
//u_char oursupp_addr[ETHER_ADDRLEN]; // ethernet address of the supplicant interface
u_char supp_addr[ETHER_ADDRLEN];
//u_char svr_addr[ETHER_ADDRLEN];
struct Global_Params_tag * global;
struct pktbuf fromsupp; // buffers of length one to store latest packet from
struct pktbuf fromsvr; // supplicant / server
//struct lib1x_nal_intfdesc * network_svr;
//struct lib1x_nal_intfdesc * network_supp;
FILE * debugsm;
//struct in_addr ourip_inaddr, svrip_inaddr;
//u_short udp_ourport, udp_svrport;
struct radius_info * rinfo; /* structure for radius related bookkeeping with respect
to sending packets to the radius server*/
struct sockaddr_in radsvraddr;
int udpsock;
struct lib1x_radius_const * rconst;
};
typedef struct Auth_Pae_tag Auth_Pae;
typedef struct lib1x_packet lib1x_packet_tag;
typedef struct lib1x_nal_intfdesc lib1x_nal_intfdesc_tag;
#ifdef START_AUTH_IN_LIB
typedef struct auth_param {
int encryption; // 2:WPA, 4:WPA2, 6:both
int wpaCipher; // 1:TKIP, 2:AES, 3:both
#ifdef RTL_WPA2
int wpa2Cipher; // 1:TKIP, 2:AES, 3:both
#endif
unsigned char ssid[40];
unsigned char psk[64];
int role; // 0:AP, 1:infra-client, 2:adhoc
int terminate; // 0:run, 1:terminate
} auth_param_t;
#endif // START_AUTH_IN_LIB
// Now the function declarations follow:
//-----------------------------------------------------
// Initialization Function
//-----------------------------------------------------
int lib1x_init_authRSNConfig(
Dot1x_Authenticator * auth);
int lib1x_init_authGlobal(
Dot1x_Authenticator * auth);
int lib1x_init_authTimer(
Dot1x_Authenticator * auth);
TxRx_Params * lib1x_init(
u_char * oursvr_addr,
u_char * svr_addr ,
u_char * oursupp_addr,
u_char * ourip_addr,
u_char * svrip_addr,
u_short udp_ourport,
u_short udp_svrport ,
u_char *dev_svr,
u_char * dev_supp);
Global_Params * lib1x_init_authenticator(
Dot1x_Authenticator * auth,
TxRx_Params * dev_txrx);
TxRx_Params * lib1x_init_txrx(
Dot1x_Authenticator *auth,
u_char * oursvr_addr,
u_char * svr_addr,
u_char * oursupp_addr,
u_char * ourip_addr,
u_char * svrip_addr,
u_short udp_ourport,
u_short udp_svrport,
#ifdef RTL_RADIUS_2SET
u_char * svrip_addr2,
u_short udp_svrport2,
u_char * acctip_addr2,
u_short udp_acctport2,
#endif
u_char * acctip_addr,
u_short udp_acctport,
u_char * dev_svr,
u_char * dev_supp);
int lib1x_init_auth(
Dot1x_Authenticator * auth);
//-----------------------------------------------------
// For 802.11 authentication and key management
//-----------------------------------------------------
void lib1x_get_NumSTA( Dot1x_Authenticator * auth);
int lib1x_do_authenticator( Dot1x_Authenticator * auth);
void lib1x_auth_process(Dot1x_Authenticator * auth );
void lib1x_reset_authenticator(Global_Params * global);
int lib1x_timer_authenticator(int signum);
//-----------------------------------------------------
// Porcedures for processing data
//-----------------------------------------------------
void lib1x_authsm_capture_supp( Global_Params *, lib1x_nal_intfdesc_tag * nal, lib1x_packet_tag * );
void lib1x_authsm_capture_svr( Global_Params *, lib1x_nal_intfdesc_tag * nal, lib1x_packet_tag * );
int lib1x_capture_control(Global_Params * global, lib1x_nal_intfdesc_tag * nal, lib1x_packet_tag * spkt);
//-----------------------------------------------------
// Procedure called by key management state machine
//-----------------------------------------------------
void lib1x_akmsm_Timer_proc(Dot1x_Authenticator * auth);
//-----------------------------------------------------
// packet xmit routines.
//-----------------------------------------------------
void lib1x_auth_txCannedSuccess( Auth_Pae * auth_pae, int identifier );
void lib1x_auth_txCannedFail( Auth_Pae * auth_pae, int identifier );
void lib1x_auth_txReqId( Auth_Pae * auth_pae, int identifier );
void lib1x_authsm_dump( FILE * fdesc, Auth_Pae * auth_pae );
//-----------------------------------------------------
// sta table management function
//-----------------------------------------------------
int lib1x_search_supp(Dot1x_Authenticator * auth , lib1x_packet_tag * spkt, u_char inttype);
int lib1x_insert_supp(Dot1x_Authenticator *auth, u_char * supp_addr);
int lib1x_del_supp(Dot1x_Authenticator *auth, u_char * supp_addr);
#endif

View File

@ -0,0 +1,63 @@
#ifndef LIB1x_BAUTH_SM_H
#define LIB1x_BAUTH_SM_H
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_bauth_sm.h
// Programmer : Arunesh Mishra
//
//
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//
//--------------------------------------------------
#define LIB1X_BSM_SUPPTIMEOUT 30
#define LIB1X_BSM_SVRTIMEOUT 30
#define LIB1X_BSM_MAXREQ 2
#include <stdio.h>
struct Auth_Pae_tag;
struct Global_Params_tag;
typedef struct Bauth_SM_tag
{
BAUTH_SM_STATE state;
int reqCount;
// A counter used to determine how many EAP Request packets
// have been sent to the Supplicant without receiving a response.
BOOLEAN rxResp; // if a EAPOL PDU of type EAP packet rcvd from supp carrying a Request
BOOLEAN aSuccess; // if Accept pkt recvd from Auth Server
BOOLEAN aFail; // true if reject pkt rcvd from auth svr.
BOOLEAN aReq; // true if eap req pkt rcvd frm auth svr.
int idFromServer; // most recent EAP success, failure or req pkt rcvd frm auth svr.
int suppTimeout;
int serverTimeout;
int maxReq;
FILE * debugsm;
} Bauth_SM;
// The functions exported.
void lib1x_bauthsm_init( Bauth_SM * bauth_sm, int maxReq, int aWhile );
void lib1x_bauthsm( struct Auth_Pae_tag * , struct Global_Params_tag * , Bauth_SM * );
BOOLEAN lib1x_trans_bauthsm( struct Auth_Pae_tag * , struct Global_Params_tag *, Bauth_SM * );
void lib1x_exec_bauthsm( struct Auth_Pae_tag * , struct Global_Params_tag * , Bauth_SM * );
void lib1x_bauthsm_abortAuth();
#endif

View File

@ -0,0 +1,42 @@
#ifndef LIB1x_CDSM_H
#define LIB1x_CDSM_H
#include "1x_types.h"
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : auth_pae.h
// Programmer : Arunesh Mishra
//
// H file for Controlled Directions State Machine
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
struct Auth_Pae_tag;
struct Global_Params_tag; /* These have been defined in 1x_common.h */
typedef struct CtrlDirSM_tag
{
CTRL_SM_STATE state;
DIRECTION adminControlledDirections;
DIRECTION operControlledDirections;
BOOLEAN bridgeDetected;
} CtrlDirSM;
void lib1x_cdsm_init( CtrlDirSM * ctrl_sm );
void lib1x_trans_cdsm( struct Auth_Pae_tag * auth_params, struct Global_Params_tag * global, CtrlDirSM * dirsm);
#endif

View File

@ -0,0 +1,690 @@
#ifndef LIB1x_COMMON_H
#define LIB1x_COMMON_H
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : common.h
// Programmer : Arunesh Mishra
//
// Contains all common declarations and definitions.
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
#include<assert.h>
#include<stdarg.h>
#include<sys/types.h>
#include<stdio.h>
#include <syslog.h> // david+2006-03-31, for add event to syslog
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "rtk_arch.h"
#ifndef RTL_WPA_CLIENT
#if !defined(CONFIG_RTL8186_TR) && !defined(CONFIG_RTL865X_AC)
#define RTL_WPA_CLIENT
//#define DBG_WPA_CLIENT
#endif
#endif
#ifdef _RTL_WPA_WINDOWS
#else
#include "1x_types.h"
#include "1x_ethernet.h"
#include "1x_kmsm_keydef.h"
#endif
#ifdef RTL_WPA2
#include "1x_list.h"
#endif
#if defined(CONFIG_RTL8186_TR) || defined(CONFIG_RTL865X_SC) || defined(CONFIG_RTL865X_AC) || defined(CONFIG_RTL865X_KLD)
#define _NOTICE "tag:NOTICE;log_num:13;msg:"
#define _CMD "exlog /tmp/log_web.lck /tmp/log_web"
#define LOG_MSG_NOTICE(fmt, args...) { \
char tmpbuf[400]; \
sprintf(tmpbuf, "%s \"%s" fmt "\"", _CMD, _NOTICE, ## args); \
system(tmpbuf); \
}
#endif
#ifdef CONFIG_IEEE80211W
union PN48 {
unsigned long long val48;
struct {
unsigned char TSC7;
unsigned char TSC6;
unsigned char TSC5;
unsigned char TSC4;
unsigned char TSC3;
unsigned char TSC2;
unsigned char TSC1;
unsigned char TSC0;
} _byte_;
};
#endif /* CONFIG_IEEE80211W */
#ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT
typedef enum { EAP_MD5=0, EAP_TLS=1, EAP_PEAP=2 } EAP_TYPE_T;
typedef enum { INSIDE_MSCHAPV2=0 } INSIDE_TYPE_T;
typedef enum { PHYBAND_OFF=0, PHYBAND_2G=1, PHYBAND_5G=2 } PHYBAND_TYPE_T;
#define MAX_EAP_USER_ID_LEN 64
#define MAX_RS_USER_NAME_LEN 64
#define MAX_RS_USER_PASS_LEN 64
#define MAX_RS_USER_CERT_PASS_LEN 64
//#define RS_USER_CERT (TOP_CONFIG_DIR "/1x/client.pem")
#define RS_USER_CERT_2G (TOP_CONFIG_DIR "/1x/client_2g.pem")
#define RS_USER_CERT_5G (TOP_CONFIG_DIR "/1x/client_5g.pem")
//#define RS_ROOT_CERT (TOP_CONFIG_DIR "/1x/ca.pem")
#define RS_ROOT_CERT_2G (TOP_CONFIG_DIR "/1x/ca_2g.pem")
#define RS_ROOT_CERT_5G (TOP_CONFIG_DIR "/1x/ca_5g.pem")
//#define XSUP_CONF_FILE (TOP_CONFIG_DIR "/1x/1x.conf")
#define XSUP_CONF_FILE_NAME_FMT (TOP_CONFIG_DIR "/1x/1x-%s.conf")
//#define XSUP_CONF_MODULE_FILE (TOP_CONFIG_DIR "/1x/1x_module.conf")
#define XSUP_MD5_CONF_MODULE_FILE (TOP_CONFIG_DIR "/1x/1x_module_md5.conf")
#define XSUP_TLS_CONF_MODULE_FILE (TOP_CONFIG_DIR "/1x/1x_module_tls.conf")
#define XSUP_PEAP_CONF_MODULE_FILE (TOP_CONFIG_DIR "/1x/1x_module_peap.conf")
#endif
#define MAX_RS_NAS_PORT_ID_LEN 64
#define IP_ADDRSIZE 50
#define INC(X) { (X) = (X) + 1; if (X > 255) X = 0; /*write(1, "\n[INC]\n", sizeof("\n[INC]\n"));*/};
#define MESS_BUF_SIZE 512
#define MESS_DBG_AUTH 1
#define MESS_DBG_AUTHSM 9
#define MESS_DBG_AUTHNET 8
#define MESS_DBG_KRCSM 5
#define MESS_DBG_KXSM 6
#define MESS_DBG_SUPP 2
#define MESS_DBG_NAL 7
#define MESS_DBG_BSM 10
#define MESS_DBG_RAD 11
#define MESS_DBG_PTSM 13
#define MESS_AUTH_LOG 4
#define MESS_ERROR_OK 16
#define MESS_ERROR_FATAL 17
#define MESS_DBG_SPECIAL 12
#define MESS_DBG_DAEMON 18
#define MESS_DBG_KEY_MANAGE 19
#define MESS_DBG_CONTROL 20 //2003-06-13
#define MESS_DBG_RSNINFO 21
#define MESS_DBG_CONFIG 22
#define MESS_DBG_ACCT 23
#define MESS_DBG_FIFO 24
#define MAX_SUPPLICANT 32
#define MAX_RCV_FIFO 2048
//#define LIB1X_RAD_SHARED 100
#define LIB1X_AUTH_INDEX 0xfff
struct PKT_LSTNR_tag;
struct PKT_XMIT_tag;
//---- Basic Timer Unit in useconds ----
//#define LIB1X_BASIC_TIMER_UNIT 100000
// kenny
//#define LIB1X_BASIC_TIMER_UNIT 1000000
#define LIB1X_BASIC_TIMER_UNIT 100000
#define SECONDS_TO_TIMERCOUNT(x) ((x*1000000)/LIB1X_BASIC_TIMER_UNIT)
#define USECONDS_TO_TIMERCOUNT(x) (x/LIB1X_BASIC_TIMER_UNIT)
// use the following macro to replace usleep interrupt by timer
#define LIB_USLEEP(x) {\
int i;\
for(i=0; i < USECONDS_TO_TIMERCOUNT(x) ; i++)\
if(usleep(x) == 0)\
break;\
}
#define INC_GLOBAL_SESSION_ID(X) ((X==0xffffffff)?X=0:X++)
typedef struct Timers_tag
{
int authWhile;
// Used by the Supplicant PAE to determine how long to wait for
// a response from the Authenticator.
int aWhile;
// Used by the Backend Authentication state machine in order to
// determine timeout conditions in the exchanges between the
// Authenticator and Supplicant or Auth Server.
int heldWhile;
// Used by Supplicant state machine to define periods of time
// during which it will not attempt to acquire an Authenticator.
int quietWhile;
// During this period Authenticator will not acquire supplicant.
int reAuthWhen;
// A timer used by the Reauthentication Timer state machine in
// order to determine when re-authentication of the Supplicant
// takes place.
int startWhen;
// Used by Supplicant PAE state machine to determine when an
// EAPOL start PDU is to be transmitted.
int txWhen;
} Timers;
struct Auth_Pae_tag;
struct Supp_Pae_tag; // these here to make "# includes" consistent
struct lib1x_ptsm;
//-----------------------------------------------------------------------
// RSN Related
//-----------------------------------------------------------------------
#define DOT11_MAX_ALGORITHMS 0x0a
typedef struct _DOT11_AlgoElement
{
u_long Index;
u_long AlgoId;
BOOLEAN Enabled;
}DOT11_AlgoElement;
typedef struct _DOT11_AlgoSuit
{
u_long NumOfAlgo;
DOT11_AlgoElement AlgoTable[DOT11_MAX_ALGORITHMS];
}DOT11_AlgoSuit;
typedef struct _DOT11_RSN_AUTHENTICATOR_VARIABLE
{
//RSN related variable
OCTET_STRING AuthInfoElement;
BOOLEAN isSupportUnicastCipher;
BOOLEAN isSupportMulticastCipher;
BOOLEAN isSupportPreAuthentication;
BOOLEAN isSupportPairwiseAsDefaultKey;
BOOLEAN Dot1xEnabled;
BOOLEAN MacAuthEnabled;
BOOLEAN RSNEnabled;
#ifdef RTL_WPA2
BOOLEAN WPAEnabled;
BOOLEAN WPA2Enabled;
#endif
BOOLEAN TSNEnabled;
int WepMode;
int NumOfUnicastCipher;
int NumOfAuthCipher;
DOT11_AlgoSuit UniCastCipherSuit;
#ifdef RTL_WPA2
DOT11_AlgoSuit WPA2UniCastCipherSuit;
#endif
DOT11_AlgoSuit MulticastCipherSuit;
DOT11_AlgoSuit AuthenticationSuit;
u_char NumOfRxTSC;
u_char MulticastCipher;
u_char AuthKeyMethod;
#ifdef CONFIG_IEEE80211W
enum mfp_options ieee80211w;
/* dot11AssociationSAQueryMaximumTimeout (in TUs) */
unsigned int assoc_sa_query_max_timeout;
/* dot11AssociationSAQueryRetryTimeout (in TUs) */
int assoc_sa_query_retry_timeout;
#endif /* CONFIG_IEEE80211W */
#ifdef HS2_SUPPORT
unsigned char bOSEN; // OSU Server-Only Authenticated L2 Encryption Network
#endif
u_char PassPhrase[64];
// size is not enough because in PasswordHash(), it will use 40 bytes long. 2005-8-8 david
// u_char PassPhraseKey[32];
u_char PassPhraseKey[40];
char ssid[64];
#ifdef RTL_RADIUS_2SET
BOOLEAN rs2MacAuthEnabled;
#endif
}DOT11_RSN_AUTHENTICATOR_VARIABLE;
typedef struct _DOT11_RSN_SUPPLICANT_VARIABLE{
OCTET_STRING SuppInfoElement;
BOOLEAN isSuppSupportUnicastCipher;
BOOLEAN isSuppSupportMulticastCipher;
BOOLEAN isSuppSupportPreAuthentication;
BOOLEAN isSuppSupportPairwiseAsDefaultKey;
BOOLEAN RSNEnabled;
#ifdef RTL_WPA2
BOOLEAN isPreAuth;
BOOLEAN WPAEnabled;
BOOLEAN WPA2Enabled;
BOOLEAN PMKCached;
struct _WPA2_PMKSA_Node* cached_pmk_node;
#endif
u_char UnicastCipher;
u_char MulticastCipher;
#ifdef CONFIG_IEEE80211W
u_char mgmt_group_cipher;
#endif /* CONFIG_IEEE80211W */
u_char NumOfRxTSC;
DOT11_AlgoSuit AuthSupportUnicastCipherSuit;
DOT11_AlgoSuit AuthSupportAuthenticationCipherSuit;
BOOLEAN isAuthSupportPreAuthentication;
BOOLEAN isAuthSupportPairwiseAsDefaultKey;
u_char AuthSupportMaxNumOfRxTSC;
}DOT11_RSN_SUPPLICANT_VARIABLE;
//-----------------------------------------------------------------------------
// Radius Key for RSN802dot1x or nonRSN802dot1x
//-----------------------------------------------------------------------------
#define RADIUS_KEY_LEN 64
typedef enum _RADIUS_KEY_STATUS
{
MPPE_SDRCKEY_NONAVALIABLE = 0x00,
MPPE_SENDKEY_AVALIABLE = 0x01,
MPPE_RECVKEY_AVALIABLE = 0x02,
MPPE_SDRCKEY_AVALIABLE = 0x03,
}RADIUS_KEY_STATUS;
typedef struct _RADIUS_KEY
{
RADIUS_KEY_STATUS Status;
OCTET_STRING SendKey;
OCTET_STRING RecvKey;
}RADIUS_KEY;
//Added to support WPA
struct Auth_PairwiseKeyManage_tag;
struct Supp_PairwiseKeyManage_tag;
struct Auth_GroupKeyManage_tag;
struct _Dot1x_Authenticator;
struct _Dot1x_Client;
//End Added
typedef struct _Dot11RSNConfigEntry {
//dot11RSNConfigIndex InterfaceIndexOrZero,
int Version;
int PairwiseKeysSupported;
OCTET_STRING MulticastCipher;
int GroupRekeyMethod;
u_long GroupRekeyTime;
u_long GroupRekeyPackets;
BOOLEAN GroupRekeyStrict;
OCTET_STRING PSKValue;
//u_char* PSKPassPhrase DisplayString,
BOOLEAN TSNEnabled;
u_long GroupMasterRekeyTime;
u_long GroupUpdateTimeOut;
u_long GroupUpdateCount;
u_long PairwiseUpdateTimeOut;
u_long PairwiseUpdateCount;
}Dot11RSNConfigEntry;
typedef struct Global_Params_tag
{
BOOLEAN authAbort;
BOOLEAN authFail;
BOOLEAN authStart;
BOOLEAN authTimeout;
BOOLEAN authSuccess;
int currentId; // Id for current authentication session
BOOLEAN initialize;
PORT_MODE_TYPE portControl;
BOOLEAN portEnabled;
PORT_STATUS_TYPE portStatus;
BOOLEAN reAuthenticate;
int receivedId;
PORT_STATUS_TYPE suppStatus;
struct lib1x_ptsm * timers;
//ROLE currentRole;
int index;
struct Auth_Pae_tag * theAuthenticator;
struct Supp_Pae_tag * theSupplicant;
struct TxRx_Params_tag * TxRx;
//Added to support WPA
struct Auth_PairwiseKeyManage_tag *akm_sm;
struct Supp_PairwiseKeyManage_tag *skm_sm;
OCTET_STRING EAPOLMsgRecvd; //The Overall 802.1x message
OCTET_STRING EAPOLMsgSend; //The Overall 802.1x message
OCTET_STRING EapolKeyMsgRecvd; //The start point of eapol-key payload
OCTET_STRING EapolKeyMsgSend;
int AuthKeyMethod;
RADIUS_KEY RadiusKey;
BOOLEAN PreshareKeyAvaliable;
#ifdef RTL_WPA2
// kenny PMK_LEN should be enough
u_char PSK[PMK_LEN];
#else
u_char PSK[PMK_LEN * 2];
#endif
u_char MaxRetryCounts;
u_char EventId;
BOOLEAN portSecure;
u_char DescriptorType; //initialize to 254 in RSN
u_char KeyDescriptorVer;
u_char CurrentAddress[ETHER_ADDRLEN];
BOOLEAN bMacAuthEnabled;
#ifdef CONFIG_IEEE80211W
BOOLEAN mgmt_frame_prot;
#endif /* CONFIG_IEEE80211W */
//RSNIE related variable
struct _DOT11_RSN_SUPPLICANT_VARIABLE RSNVariable;
Dot11RSNConfigEntry Dot11RSNConfig;
struct _Dot1x_Authenticator *auth;
//End Added WPA
} Global_Params;
typedef struct TxRx_Params_tag
{
u_char oursvr_addr[ETHER_ADDRLEN]; // ethernet address of the server interface
u_char oursupp_addr[ETHER_ADDRLEN]; // ethernet address of the supplicant interface
//u_char supp_addr[ETHER_ADDRLEN];
u_char svr_addr[ETHER_ADDRLEN];
// Device name
u_char * device_supp;
u_char * device_svr;
char * device_wlan0;
// Interface to three daemon (1)ethernet (2)wireless (3)driver
struct lib1x_nal_intfdesc * network_svr;
struct lib1x_nal_intfdesc * network_supp;
#ifdef RTL_WPA2_PREAUTH
struct lib1x_nal_intfdesc * network_ds; // via the DS, i.e. eth0 or br0?
#endif
int fd_control;
FILE * debugsm;
struct in_addr ourip_inaddr, svrip_inaddr, acctip_inaddr;
u_short udp_ourport;
u_short udp_svrport;
u_short udp_acctport;
struct sockaddr_in radsvraddr;
struct sockaddr_in acctsvraddr;
#ifdef RTL_RADIUS_2SET
struct lib1x_nal_intfdesc * network_svr2;
struct in_addr svrip_inaddr2;
u_short udp_svrport2;
struct sockaddr_in radsvraddr2;
u_short flag_replaced;
struct in_addr acctip_inaddr2;
u_short udp_acctport2;
struct sockaddr_in acctsvraddr2;
#endif
u_char GlobalRadId;
// Added to support fifo architecture
int readfifo;
int dummyfd;
u_char RecvBuf[MAX_RCV_FIFO];
OCTET_STRING RListenFIFO;
} TxRx_Params;
typedef enum { DISABLE, ENABLE } Switch;
typedef struct _Dot1x_Supplicant
{
int index;
BOOLEAN isEnable;
BOOLEAN isEAPCapable;
//unsigned char addr[ETHER_ADDRLEN];
Global_Params *global;
} Dot1x_Supplicant;
#if 0
typedef struct
{
unsigned short aid;
unsigned char addr[6];
unsigned long tx_packets;
unsigned long rx_packets;
unsigned long expired_time; // 10 msec unit
unsigned short flags;
unsigned char TxOperaRate;
unsigned char rssi;
unsigned long link_time; // 1 sec unit
unsigned long tx_fail;
} RTL_STA_INFO;
#endif
typedef struct _sta_info_2_web {
unsigned short aid;
unsigned char addr[6];
unsigned long tx_packets;
unsigned long rx_packets;
unsigned long expired_time; // 10 msec unit
unsigned short flags;
unsigned char TxOperaRate;
unsigned char rssi;
unsigned long link_time; // 1 sec unit
unsigned long tx_fail;
unsigned long tx_bytes;
unsigned long rx_bytes;
unsigned char resv[8];
} sta_info_2_web;
#define RTL_STA_INFO sta_info_2_web
typedef struct _Dot1x_Authenticator
{
int MaxSupplicant;
int NumOfSupplicant;
ROLE currentRole;
TxRx_Params *GlobalTxRx;
Dot1x_Supplicant *Supp[MAX_SUPPLICANT];
OCTET_STRING RadShared; /* NAS and RADIUS */
OCTET_STRING AcctShared;
LARGE_INTEGER Dot1xKeyReplayCounter;
u_long UsePassphrase;
u_long AuthTimerCount;
u_long KeyManageTimerCount;
u_long SessionInfoTimerCount; // Abocom
u_long IgnoreEAPOLStartCounter;
u_char svrip[IP_ADDRSIZE+1];
u_short udp_svrport;
#ifdef RTL_RADIUS_2SET
u_short use_2nd_rad;
u_char svrip2[IP_ADDRSIZE+1];
u_short udp_svrport2;
OCTET_STRING RadShared2;
u_char acctip2[IP_ADDRSIZE+1];
u_short udp_acctport2;
OCTET_STRING AcctShared2;
#endif
u_char acctip[IP_ADDRSIZE+1];
u_short udp_acctport;
u_char WepGroupKey[32];
//Added to support WPA
struct Auth_GroupKeyManage_tag *gk_sm;
OCTET32_INTEGER Counter;
u_char CurrentAddress[ETHER_ADDRLEN];
DOT11_RSN_AUTHENTICATOR_VARIABLE RSNVariable;
Dot11RSNConfigEntry Dot11RSNConfig;
u_char IoctlBuf[1024];
u_long IoctlBufLen;
BOOLEAN IoctlFlag;
//end Added
//Accounting
u_long InterimTimeout;
BOOLEAN SessionTimeoutEnabled;
BOOLEAN IdleTimeoutEnabled;
BOOLEAN AccountingEnabled;
BOOLEAN UpdateInterimEnabled;
u_long GlobalSessionId;
Dot1x_Supplicant *authGlobal;
// david, fix to 128. If support sta is greater than 128 in wlan driver,
// this value need be modified.
// RTL_STA_INFO StaInfo[MAX_SUPPLICANT+1];
RTL_STA_INFO StaInfo[128+1];
//-------------------------------------------------------------------------
//Server config
u_long rsMaxReq;
u_long rsAWhile;
u_long rsReAuthTO;
u_long accountRsMaxReq;
u_long accountRsAWhile;
#ifdef RTL_WPA_CLIENT
struct _Dot1x_Client *client;
#endif
#ifdef RTL_WPA2
struct list_head pmk_cache;
#endif
#ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT
char eapType;
char eapInsideType;
char eapUserId[MAX_EAP_USER_ID_LEN+1];
char rsUserName[MAX_RS_USER_NAME_LEN+1];
char rsUserPasswd[MAX_RS_USER_PASS_LEN+1];
char rsUserCertPasswd[MAX_RS_USER_CERT_PASS_LEN+1];
char rsBandSel;
#endif
#ifdef CONFIG_RTL8196C_AP_HCM
unsigned char hostmac[13];
unsigned int if_index;
#endif
char rsNasPortId[MAX_RS_NAS_PORT_ID_LEN];
} Dot1x_Authenticator;
void lib1x_print_etheraddr( char * s, u_char * addr );
#ifndef DEBUG_DISABLE //sc_yang
void lib1x_message( int type, char * msg, ... );
void lib1x_hexdump( FILE * fdesc, u_char * pkt, int numBytes );
void lib1x_totext_authpaestate( FILE * fdesc, AUTH_PAE_STATE state );
void lib1x_totext_bauthsmstate( FILE * fdesc, BAUTH_SM_STATE state );
void lib1x_chardump( FILE * fdesc, u_char * pkt, int numBytes );
void lib1x_hexdump2(int type, char *fun, u_char *buf, int size, char *comment);
void lib1x_PrintAddr(u_char *ucAddr);
void DUMP_GLOBAL_PARAMS( Global_Params *g, u_char *exp );
#else
#define lib1x_message(type, msg...) do{}while(0)
#define lib1x_hexdump(a, b, c) do{}while(0)
#define lib1x_totext_authpaestate(a, b) do{}while(0)
#define lib1x_totext_bauthsmstate(a, b) do{}while(0)
#define lib1x_chardump(a, b, c) do{}while(0)
#define lib1x_hexdump2(a, b, c, e , f) do{}while(0)
#define lib1x_PrintAddr(a) do{}while(0)
#define DUMP_GLOBAL_PARAMS(a, b) do{}while(0)
#endif
#ifdef CONFIG_IEEE80211W
#define PMFDEBUG(fmt, args...) printf("[%s %d]"fmt,__FUNCTION__,__LINE__,## args)
//#define PMFDEBUG(fmt, args...)
#endif /* CONFIG_IEEE80211W */
//sc_yang
extern void * lib1x_global_signal_info;
// This variable points to struct lib1x_ptsm , the port timers state machine struct,
// because we need the signal handler to access some global variable.
extern u_char dev_supp[]; // david+2006-03-31, for add event to syslog
#ifdef _ABOCOM
#define ABOCOM_ADD_STA 0
#define ABOCOM_DEL_STA 1
void lib1x_abocom(u_char *pucAddr, int ulCommandType);
#endif
#define lib1x_Little_S2N(s,c) (*((c) )=(unsigned char)(((s))&0xff), \
*((c)+1)=(unsigned char)(((s)>>8)&0xff))
#define lib1x_Little_N2S(c,s) s = 0,\
(s =((unsigned long)(*((c) ))), \
s|=( (unsigned long) (*((c)+1))<<8) )
#define lib1x_S2N(s,c) (*((c) )=(unsigned char)(((s)>>8)&0xff), \
*((c)+1)=(unsigned char)(((s) )&0xff))
#define lib1x_N2S(c,s) s = 0,\
(s =((unsigned long)(*((c) )))<<8, \
s|=((unsigned long)(*((c)+1))))
#define lib1x_L2N(l,c) (*((c) )=(unsigned char)(((l)>>24)&0xff), \
*((c)+1)=(unsigned char)(((l)>>16)&0xff), \
*((c)+2)=(unsigned char)(((l)>> 8)&0xff), \
*((c)+3)=(unsigned char)(((l) )&0xff))
#define lib1x_N2L(c,l) l = 0,\
(l =((unsigned long)(*((c) )))<<24, \
l|=((unsigned long)(*((c)+1)))<<16, \
l|=((unsigned long)(*((c)+2)))<< 8, \
l|=((unsigned long)(*((c)+3))))
//----------------------------------------------------------------
// 1x_kmsm_prf.c
//----------------------------------------------------------------
int PasswordHash (
char *password,
int passwordlength,
unsigned char *ssid,
int ssidlength,
unsigned char *output);
#ifdef RTL_WPA2
//----------------------------------------------------------------
// PMK Cache
//----------------------------------------------------------------
struct _WPA2_PMKSA
{
u_char pmkid[PMKID_LEN];
// u_char aa[6]; // Authenticator MAC Address
u_char pmk[PMK_LEN];
// u_long lifetime;
u_char akmp;
u_char spa[ETHER_ADDRLEN]; // Supplicant MAC Address
};
struct _WPA2_PMKSA_Node
{
struct list_head node;
struct _WPA2_PMKSA pmksa;
};
#endif /* RTL_WPA2 */
#endif /* LIB1x_COMMON_H */

View File

@ -0,0 +1,95 @@
#ifndef _CONFIG_PARSE_H
#define _CONFIG_PARSE_H
#define CONFIG_PARSE_TAG 80
#define CONFIG_PARSE_VALUE 80
typedef enum { ERROR_FILE_NOTEXIST = -1, ERROR_UNDEFINE_PARAMETER = -2,
ERROR_UNDEFINE_TAG = -3 } CONFIG_ERROR_ID;
#define CFG_STRERROR_FILE_NOTEXIST "Configuration file not exist"
#define CFG_STRERROR_UNDEFINE_PARAMETER "Undefine parameter in configuration file"
#define CFG_STRERROR_UNDEFINE_TAG "Undefine tag in configuration file"
typedef enum { tagUnicastCipher = 0, tagMulticastCipher = 1, tagAuthKeyMethod = 2} CONFIG_TAG_TABLE;
char ConfigTag[][32] =
{
"ssid",
"encryption",
"enable1x",
"enableMacAuth",
"supportNonWpaClient",
"wepKey",
"wepGroupKey",
"authentication",
"unicastCipher",
#ifdef RTL_WPA2
"wpa2UnicastCipher",
"enablePreAuth",
#endif
"usePassphrase",
"groupRekeyTime",
"psk",
"rsPort",
"rsIP",
"rsPassword",
#ifdef RTL_RADIUS_2SET
"rs2Port",
"rs2IP",
"rs2Password",
"rs2enableMacAuth",
#endif
#ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT
"eapType",
"eapInsideType",
"eapUserId",
"rsUserName",
"rsUserPasswd",
"rsUserCertPasswd",
"rsBandSel",
#endif
"rsMaxReq",
"rsAWhile",
"rsNasId",
"rsReAuthTO",
"accountRsEnabled",
"accountRsPort",
"accountRsIP",
"accountRsPassword",
#ifdef RTL_RADIUS_2SET
"accountRs2Port",
"accountRs2IP",
"accountRs2Password",
#endif
"accountRsMaxReq",
"accountRsAWhile",
"accountRsUpdateEnabled",
"accountRsUpdateTime",
#ifdef CONFIG_RTL8196C_AP_HCM
"hostmac",
#endif
#ifdef CONFIG_IEEE80211W
"ieee80211w",
"sha256",
#endif /* CONFIG_IEEE80211W */
"NasPortId",
};
/**
* Reads a tag out of a file in the form
* tag = value
*
* return 0 on success -1 on fail
*/
int configParse(char *, /* File name */
char *, /* Tag */
char * /* value */
);
#endif /* _CONFIG_PARSE_H_ */
/*** EOF ***/

View File

@ -0,0 +1,24 @@
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_eap.h
// Programmer : Arunesh Mishra
//
// Extensible Authentication Protocol routines
// H FILE
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
#ifndef 1X_EAP_H
#define 1X_EAP_H
#endif

View File

@ -0,0 +1,114 @@
#ifndef LIB1x_EAPOL_H
#define LIB1x_EAPOL_H
//#include <libnet.h>
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_eapol.h
// Programmer : Arunesh Mishra
//
// This contains the EAPOL packet routine
// declarations.
//
//
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
#define LIB1X_EAPOL_HDRLEN 4 // Just the header Note:
// is different from struct
#define LIB1X_EAPOL_LOGOFF 2 //0000 0010B
#define LIB1X_EAPOL_EAPPKT 0 //0000 0000B
#define LIB1X_EAPOL_START 1 //0000 0001B
#define LIB1X_EAPOL_KEY 3 //0000 0011B
#define LIB1X_EAPOL_ENCASFALERT 4 //0000 0100B
#ifdef _DATA_PATH
#define REALTEK_802dot1x_TYPE 0xcc
#endif
#define LIB1X_EAP_REQUEST 1
#define LIB1X_EAP_RESPONSE 2
#define LIB1X_EAP_SUCCESS 3
#define LIB1X_EAP_FAILURE 4
#define LIB1X_EAP_HDRLEN 4
#define LIB1X_EAP_RRIDENTITY 1
#define LIB1X_EAP_RRNOTIF 2
#define LIB1X_EAP_RRNAK 3
#define LIB1X_EAP_RRMD5 4
#define LIB1X_EAP_RROTP 5
#define LIB1X_EAP_RRGEN 6
#define LIB1x_EAP_RRLEN 1
#define LIB1X_EAPOL_VER 1 //00000001B
#define LIB1X_EAPOLKEY_HDRLEN 44
#define LIB1X_RC_LEN 8
#define LIB1X_IV_LEN 16
#define LIB1X_MIC_LEN 16
#define LIB1X_KEY_TYPE_RC4 1
#pragma pack (1) // Set our value.
struct lib1x_eapol
{
// u_short ether_type; // not including this here .. it overlaps with the ethernet header.
u_char protocol_version;
u_char packet_type; // This makes it odd in number !
u_short packet_body_length;
};
struct lib1x_eap
{
u_char code; // Identifies the type of EAP packet.
u_char identifier; // Aids in matching responses with requests.
u_short length; // Length of EAP packet including code, id, len, data fields
};
#define EAPOL_PAIRWISE_KEY 0x80
#define EAPOL_GROUP_KEY 0
#define EAPOL_PAIRWISE_INDEX 0x3
#define EAPOL_GROUP_INDEX 0x0
struct lib1x_eapolkey_dot1x
{
u_char type;
u_short length;
u_char counter[LIB1X_RC_LEN];
u_char iv[LIB1X_IV_LEN];
u_char index;
u_char mic[LIB1X_MIC_LEN];
u_char material[1];
};
struct lib1x_eap_rr
{
u_char type; // The bytes after this are the data corresponding to the RR type
};
void lib1x_construct_eapol_frame( struct lib1x_eapol * the_header, u_char * packet );
//sc_yang
#pragma pack () // Set our value.
#endif

View File

@ -0,0 +1,36 @@
#ifndef LIB1X_ETHERNET_H
#define LIB1X_ETHERNET_H
#include <sys/types.h>
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : lib1x_ethernet.h
// Programmer : Arunesh Mishra
// Contains some declarations for the 802.3 ethernet.
//
//
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//
//--------------------------------------------------
#define ETHER_ADDRLEN 6
#define ETHER_HDRLEN 14
#define LIB1X_ETHER_EAPOL_TYPE 0x888E
#ifdef RTL_WPA2_PREAUTH
#define PREAUTH_ETHER_EAPOL_TYPE 0x88C7
#endif
#define LIB1X_ETHER_IP 0x800
struct lib1x_ethernet
{
u_char ether_dhost[ETHER_ADDRLEN]; /* destination ethernet address */
u_char ether_shost[ETHER_ADDRLEN]; /* source ethernet address */
u_short ether_type; /* packet type ID */
};
#endif

View File

@ -0,0 +1,34 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "rtk_arch.h"
//#define DAEMON_FIFO "/root/802.1x/open1x/src/FIFO/daemon_fifo"
#ifdef _DAEMON_SIDE
#define DAEMON_FIFO (TOP_CONFIG_DIR "/auth-%s.fifo")
#else
//sc_yang for dual mode
#define DAEMON_FIFO (TOP_CONFIG_DIR "/auth-%s.fifo")
#endif
#ifdef _LISTEN_SIDE
#define LISTEN_FIFO "fifo.dat"
#else
#define LISTEN_FIFO "fifo.dat"
#endif
#define MAXLINE 20000
#define RWFIFOSIZE 1600 // jimmylin: org: 160, for passing EAP packet by event queue
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
/* default permission for new files */
#define FIFO_TYPE_WLISTEN 0x01
#define FIFO_TYPE_DLISTEN 0x02
#define FIFO_TYPE_RLISTEN 0x03
#define FIFO_HEADER_LEN 5

View File

@ -0,0 +1,260 @@
#ifdef _RTL_WPA_WINDOWS
typedef unsigned short u_short;
typedef unsigned char u_char;
#else
#include <sys/types.h>
#endif
#include "1x_common.h"
#define NONE -1
#define CIPHER_WEP40 0
//#define CIPHER_TKIP 1
#define CIPHER_AESCCMP 2
#define CIPHER_AESWRAP 3
#define CIPHER_WEP104 4
#define IEEE802_1X 0
#define ELEMENTID 0xdd
#define GROUPFLAG 0x02
#define REPLAYBITSSHIFT 2
#define REPLAYBITS 0x03
struct InfoElement {
u_char Elementid;
u_char length;
u_char oui[4];
u_short version;
u_char multicast[4];
u_short ucount;
struct {
u_char oui[4];
}unicast[1]; // the rest is variable so need to
// overlay ieauth structure
};
struct _ieauth {
u_short acount;
struct {
u_char oui[4];
}auth[1];
};
//---- Error number is the negative value
//---- that follows 802/11i D3.0 Failure Association Request reason code ----
typedef enum{ERROR_BUFFER_TOO_SMALL = -1, ERROR_INVALID_PARA = -2, ERROR_INVALID_RSNIE = -13,
ERROR_INVALID_MULTICASTCIPHER = -18, ERROR_INVALID_UNICASTCIPHER = -19,
ERROR_INVALID_AUTHKEYMANAGE = -20,
ERROR_UNSUPPORTED_RSNEVERSION = -21, ERROR_INVALID_CAPABILITIES = -22
#ifdef CONFIG_IEEE80211W
,ERROR_MGMT_FRAME_PROTECTION_VIOLATION = -31
#endif /* CONFIG_IEEE80211W */
}INFO_ERROR;
#define RSN_STRERROR_BUFFER_TOO_SMALL "Input Buffer too small"
#define RSN_STRERROR_INVALID_PARAMETER "Invalid RSNIE Parameter"
#define RSN_STRERROR_INVALID_RSNIE "Invalid RSNIE"
#define RSN_STRERROR_INVALID_MULTICASTCIPHER "Multicast Cipher is not valid"
#define RSN_STRERROR_INVALID_UNICASTCIPHER "Unicast Cipher is not valid"
#define RSN_STRERROR_INVALID_AUTHKEYMANAGE "Authentication Key Management Protocol is not valid"
#define RSN_STRERROR_UNSUPPORTED_RSNEVERSION "Unsupported RSNE version"
#define RSN_STRERROR_INVALID_CAPABILITIES "Invalid RSNE Capabilities"
#ifdef CONFIG_IEEE80211W
#define RSN_STRERROR_MGMT_FRAME_PROTECTION_VIOLATION "Robust management frame policy violation"
#endif /* CONFIG_IEEE80211W */
#define RSN_ELEMENT_ID 221
#ifdef RTL_WPA2
#define WPA_ELEMENT_ID 0xDD
#define WPA2_ELEMENT_ID 0x30
#endif
#define RSN_VER1 0x01
//#define DOT11_MAX_CIPHER_ALGORITHMS 0x0a
typedef struct _DOT11_RSN_IE_HEADER {
u_char ElementID;
u_char Length;
u_char OUI[4];
u_short Version;
}DOT11_RSN_IE_HEADER;
#ifdef RTL_WPA2
#define WPA2_ELEMENT_ID 0x30
typedef struct _DOT11_WPA2_IE_HEADER {
u_char ElementID;
u_char Length;
u_short Version;
}DOT11_WPA2_IE_HEADER;
#endif
typedef struct _DOT11_RSN_IE_SUITE{
u_char OUI[3];
u_char Type;
}DOT11_RSN_IE_SUITE;
typedef struct _DOT11_RSN_IE_COUNT_SUITE{
u_short SuiteCount;
DOT11_RSN_IE_SUITE dot11RSNIESuite[DOT11_MAX_ALGORITHMS];
}DOT11_RSN_IE_COUNT_SUITE, *PDOT11_RSN_IE_COUNT_SUITE;
typedef union _DOT11_RSN_CAPABILITY{
u_short shortData;
u_char charData[2];
#if 0
#ifdef RTL_WPA2
struct
{
#ifdef CONFIG_IEEE80211W
u_short MFPC:1; // B7
u_short MFPR:1; // B6
#else
u_short Reserved1:2; // B7 B6
#endif /* CONFIG_IEEE80211W */
u_short GtksaReplayCounter:2; // B5 B4
u_short PtksaReplayCounter:2; // B3 B2
u_short NoPairwise:1; // B1
u_short PreAuthentication:1; // B0
u_short Reserved2:8;
}field;
#else
struct
{
u_short PreAuthentication:1;
u_short PairwiseAsDefaultKey:1;
u_short NumOfReplayCounter:2;
u_short Reserved:12;
}field;
#endif
#endif //if 0
#ifdef RTL_WPA2
struct
{
#ifdef LIBNET_BIG_ENDIAN
#ifdef CONFIG_IEEE80211W
unsigned short MFPC:1; // B7
unsigned short MFPR:1; // B6
#else
unsigned short Reserved1:2; // B7 B6
#endif
unsigned short GtksaReplayCounter:2; // B5 B4
unsigned short PtksaReplayCounter:2; // B3 B2
unsigned short NoPairwise:1; // B1
unsigned short PreAuthentication:1; // B0
unsigned short Reserved2:8;
#else
unsigned short PreAuthentication:1; // B0
unsigned short NoPairwise:1; // B1
unsigned short PtksaReplayCounter:2; // B3 B2
unsigned short GtksaReplayCounter:2; // B5 B4
#ifdef CONFIG_IEEE80211W
unsigned short MFPR:1; // B6
unsigned short MFPC:1; // B7
#else
unsigned short Reserved1:2; // B7 B6
#endif
unsigned short Reserved2:8;
#endif
}field;
#else
struct
{
#ifdef LIBNET_BIG_ENDIAN
unsigned short PreAuthentication:1;
unsigned short PairwiseAsDefaultKey:1;
unsigned short NumOfReplayCounter:2;
unsigned short Reserved:12;
#else
unsigned short Reserved1:4;
unsigned short NumOfReplayCounter:2;
unsigned short PairwiseAsDefaultKey:1;
unsigned short PreAuthentication:1;
unsigned short Reserved2:8;
#endif
}field;
#endif
}DOT11_RSN_CAPABILITY;
#define DOT11_NUM_ENTRY 0x0a
//-------------------------------------------------
//-- Unicast Cipher Suite configuration table
//-------------------------------------------------
//--dot11RSNConfigUnicastCiphersEntry OBJECT-TYPE
//"The table entry, indexed by the interface index (or all interfaces) and the unicast cipher."
//-- dot11RSNConfigUnicastCiphersTable OBJECT-TYPE
//"This table lists the unicast ciphers supported by this entity.
//It allows enabling and disabling of each unicast cipher by network management.
//The Unicast Cipher Suite list in the RSN Information Element is formed using the information in this table."
typedef struct _Dot11RSNConfigUnicastCiphersEntry
{
u_long Index;
OCTET_STRING Cipher; //It consists of an OUI (the three most significant octets) and a cipher suite identifier (the least significant octet)."
BOOLEAN Enabled;
}Dot11RSNConfigUnicastCiphersEntry;
typedef struct _Dot11RSNConfigUnicastCiphersTable
{
u_long NumEntry;
Dot11RSNConfigUnicastCiphersEntry Table[DOT11_NUM_ENTRY];
}Dot11RSNConfigUnicastCiphersTable;
//-----------------------------------------------------------
// The Authentication Suites Table
//-----------------------------------------------------------
//----dot11RSNConfigAuthenticationSuitesEntry OBJECT-TYPE
//"An entry (row) in the dot11RSNConfigAuthenticationSuitesTable."
//----dot11RSNConfigAuthenticationSuitesTable OBJECT-TYPE
//"This table lists the authentication suites supported by this entity.
//Each authentication suite can be individually enabled and disabled.
//The Authentication Suite List in the RSN IE is formed using the information in this table."
typedef struct _Dot11RSNConfigAuthenticationSuitesEntry
{
u_long Index;
OCTET_STRING Suite; //It consists of an OUI (the three most significant octets) and a cipher suite identifier (the least significant octet). "
BOOLEAN Enabled;
}Dot11RSNConfigAuthenticationSuitesEntry;
typedef struct _Dot11RSNConfigAuthenticationSuitesTable{
u_long NumEntry;
Dot11RSNConfigUnicastCiphersEntry Table[DOT11_NUM_ENTRY];
}Dot11RSNConfigAuthenticationSuitesTable;
char * lib1x_authRSN_err(int err);
int lib1x_authRSN_constructIE(Dot1x_Authenticator * auth,
u_char * pucOut,
int * usOutLen,
BOOLEAN bAttachIEHeader);
int lib1x_authRSN_parseIE(Dot1x_Authenticator * auth,
Global_Params * global,
u_char * pucIE, u_long ulIELength);
//int lib1x_authRSN_parseIE(Dot1x_Authenticator * auth,
// Global_Params * global,
// u_char * pucIE, u_long ulIELength);
#ifdef RTL_WPA2
int lib1x_authRSN_match(Dot1x_Authenticator * auth, Global_Params * global, BOOLEAN bWPA2);
#else
int lib1x_authRSN_match(Dot1x_Authenticator * auth, Global_Params * global);
#endif

View File

@ -0,0 +1,637 @@
/************************* 802.1x Message ***************************/
/*
* Reason code for Disconnect
*/
typedef enum _ReasonCode{
unspec_reason = 0x01,
auth_not_valid = 0x02,
deauth_lv_ss = 0x03,
inactivity = 0x04,
ap_overload = 0x05,
class2_err = 0x06,
class3_err = 0x07,
disas_lv_ss = 0x08,
asoc_not_auth = 0x09,
#ifdef _RTL_WPA_UNIX
RSN_invalid_info_element = 13,
RSN_MIC_failure = 14,
RSN_4_way_handshake_timeout = 15,
RSN_diff_info_element = 17,
RSN_multicast_cipher_not_valid = 18,
RSN_unicast_cipher_not_valid = 19,
RSN_AKMP_not_valid = 20,
RSN_unsupported_RSNE_version = 21,
RSN_invalid_RSNE_capabilities = 22,
RSN_ieee_802dot1x_failed = 23,
//belowing are Realtek definition
RSN_PMK_not_avaliable = 24,
#endif
expire = 30,
session_timeout = 31,
acct_idle_timeout = 32,
acct_user_request = 33
}ReasonCode;
/*
* Data structure for ioctl with driver
*/
#define MAXRSNIELEN 128
#define MacAddrLen 6
#ifdef WIFI_SIMPLE_CONFIG
#define PROBEIELEN 128
#endif
typedef unsigned char DOT11_KEY_RSC[8];
typedef enum{
DOT11_KeyType_Group = 0,
DOT11_KeyType_Pairwise = 1
#ifdef CONFIG_IEEE80211W
,DOT11_KeyType_IGTK = 2
#endif /* CONFIG_IEEE80211W */
}DOT11_KEY_TYPE;
typedef enum{
DOT11_KeyUsage_ENC,
DOT11_KeyUsage_MIC
}DOT11_KEY_USAGE;
typedef enum{
DOT11_Role_Auth,
DOT11_Role_Supp
}DOT11_ROLE;
typedef enum{
DOT11_VARIABLE_MACEnable,
DOT11_VARIABLE_SystemAuthControl,
DOT11_VARIABLE_AuthControlledPortStatus,
DOT11_VARIABLE_AuthControlledPortControl,
DOT11_VARIABLE_AuthenticationType,
DOT11_VARIABLE_KeyManagement,
DOT11_VARIABLE_MulticastCipher,
DOT11_VARIABLE_UnicastCipher
} DOT11_VARIABLE_TYPE;
typedef enum{
DOT11_SysAuthControl_Disabled,
DOT11_SysAuthControl_Enabled
} DOT11_SYSTEM_AUTHENTICATION_CONTROL;
typedef enum{
DOT11_PortControl_ForceUnauthorized,
DOT11_PortControl_ForceAuthorized,
DOT11_PortControl_Auto
} DOT11_PORT_CONTROL;
typedef enum{
DOT11_PortStatus_Unauthorized,
DOT11_PortStatus_Authorized
}DOT11_PORT_STATUS;
typedef enum{
DOT11_Association_Fail,
DOT11_Association_Success
}DOT11_ASSOCIATION_RESULT;
typedef enum{
DOT11_AuthKeyType_RSNReserved = 0,
DOT11_AuthKeyType_RSN = 1,
DOT11_AuthKeyType_RSNPSK = 2,
DOT11_AuthKeyType_NonRSN802dot1x = 3,
#ifdef CONFIG_IEEE80211W
DOT11_AuthKeyType_802_1X_SHA256 = 5,
DOT11_AuthKeyType_PSK_SHA256 = 6,
#endif /* CONFIG_IEEE80211W */
DOT11_AuthKeyType_PRERSN = 255,
} DOT11_AUTHKEY_TYPE;
typedef enum{
DOT11_Ioctl_Query = 0,
DOT11_Ioctl_Set = 1,
} DOT11_Ioctl_Flag;
typedef enum{
DOT11_ENC_NONE = 0,
DOT11_ENC_WEP40 = 1,
DOT11_ENC_TKIP = 2,
DOT11_ENC_WRAP = 3,
DOT11_ENC_CCMP = 4,
DOT11_ENC_WEP104= 5,
#ifdef CONFIG_IEEE80211W
DOT11_ENC_BIP = 6,
DOT11_ENC_NOGA = 7, //Group addressed traffic not allowed
#endif /* CONFIG_IEEE80211W */
DOT11_ENC_UNKNOWN = 255,
} DOT11_ENC_ALGO;
typedef enum{
DOT11_EVENT_NO_EVENT = 1,
DOT11_EVENT_REQUEST = 2,
DOT11_EVENT_ASSOCIATION_IND = 3,
DOT11_EVENT_ASSOCIATION_RSP = 4,
DOT11_EVENT_AUTHENTICATION_IND = 5,
DOT11_EVENT_REAUTHENTICATION_IND = 6,
DOT11_EVENT_DEAUTHENTICATION_IND = 7,
DOT11_EVENT_DISASSOCIATION_IND = 8,
DOT11_EVENT_DISCONNECT_REQ = 9,
DOT11_EVENT_SET_802DOT11 = 10,
DOT11_EVENT_SET_KEY = 11,
DOT11_EVENT_SET_PORT = 12,
DOT11_EVENT_DELETE_KEY = 13,
DOT11_EVENT_SET_RSNIE = 14,
DOT11_EVENT_GKEY_TSC = 15,
DOT11_EVENT_MIC_FAILURE = 16,
DOT11_EVENT_ASSOCIATION_INFO = 17,
DOT11_EVENT_INIT_QUEUE = 18,
DOT11_EVENT_EAPOLSTART = 19,
//2003-07-30 ------------
DOT11_EVENT_ACC_SET_EXPIREDTIME = 31,
DOT11_EVENT_ACC_QUERY_STATS = 32,
DOT11_EVENT_ACC_QUERY_STATS_ALL = 33,
//-----------------------
// --- 2003-08-04 ---
DOT11_EVENT_REASSOCIATION_IND = 34,
DOT11_EVENT_REASSOCIATION_RSP = 35,
//-----------------------
DOT11_EVENT_STA_QUERY_BSSID = 36,
DOT11_EVENT_STA_QUERY_SSID = 37,
// jimmylin: pass EAP packet by event queue
DOT11_EVENT_EAP_PACKET = 41,
#ifdef RTL_WPA2
DOT11_EVENT_EAPOLSTART_PREAUTH = 45,
DOT11_EVENT_EAP_PACKET_PREAUTH = 46,
#endif
#ifdef RTL_WPA2_CLIENT
DOT11_EVENT_WPA2_MULTICAST_CIPHER = 47,
#endif
DOT11_EVENT_WPA_MULTICAST_CIPHER = 48,
#ifdef AUTO_CONFIG
DOT11_EVENT_AUTOCONF_ASSOCIATION_IND = 50,
DOT11_EVENT_AUTOCONF_ASSOCIATION_CONFIRM = 51,
DOT11_EVENT_AUTOCONF_PACKET = 52,
DOT11_EVENT_AUTOCONF_LINK_IND = 53,
#endif
#ifdef WIFI_SIMPLE_CONFIG
DOT11_EVENT_WSC_SET_IE = 55,
DOT11_EVENT_WSC_PROBE_REQ_IND = 56,
DOT11_EVENT_WSC_PIN_IND = 57,
DOT11_EVENT_WSC_ASSOC_REQ_IE_IND = 58,
/* WPS2DOTX ; support Assigned MAC Addr,Assigned SSID,dymanic change STA's PIN code, 2011-0505 */
DOT11_EVENT_WSC_SET_MY_PIN = 102,
DOT11_EVENT_WSC_SPEC_SSID = 103,
DOT11_EVENT_WSC_SPEC_MAC_IND = 104,
/* WPS2DOTX ;support Assigned MAC Addr,Assigned SSID,dymanic change STA's PIN code, 2011-0505 */
#ifdef CONFIG_IWPRIV_INTF
DOT11_EVENT_WSC_START_IND = 70,
//EV_MODE, EV_STATUS, EV_MEHOD, EV_STEP, EV_OOB
DOT11_EVENT_WSC_MODE_IND = 71,
DOT11_EVENT_WSC_STATUS_IND = 72,
DOT11_EVENT_WSC_METHOD_IND = 73,
DOT11_EVENT_WSC_STEP_IND = 74,
DOT11_EVENT_WSC_OOB_IND = 75,
#endif //ifdef CONFIG_IWPRIV_INTF
#endif
/*WPS2DOTX*/
#ifdef CONFIG_IEEE80211W
DOT11_EVENT_SET_PMF = 120,
DOT11_EVENT_GET_IGTK_PN = 121,
#endif /* CONFIG_IEEE80211W */
DOT11_EVENT_MAX = 200,
} DOT11_EVENT;
/* -------------------- MESSAGE DATA STRUCTURE--------------------- */
typedef struct _DOT11_GENERAL{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char *Data;
}DOT11_GENERAL;
typedef struct _DOT11_NOEVENT{
unsigned char EventId;
unsigned char IsMoreEvent;
}DOT11_NO_EVENT;
typedef struct _DOT11_REQUEST{
unsigned char EventId;
}DOT11_REQUEST;
#ifdef RTL_WPA2_CLIENT
typedef struct _DOT11_WPA2_MULTICAST_CIPHER{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char MulticastCipher;
}DOT11_WPA2_MULTICAST_CIPHER;
#endif /* RTL_WPA2_CLIENT */
typedef struct _DOT11_WPA_MULTICAST_CIPHER{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char MulticastCipher;
}DOT11_WPA_MULTICAST_CIPHER;
typedef struct _DOT11_ASSOCIATION_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned short RSNIELen;
char RSNIE[MAXRSNIELEN];
}DOT11_ASSOCIATION_IND;
typedef struct _DOT11_ASSOCIATION_RSP{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned char Status;
}DOT11_ASSOCIATION_RSP;
// --- 2003-08-04 ---
typedef struct _DOT11_REASSOCIATION_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned short RSNIELen;
char RSNIE[MAXRSNIELEN];
char OldAPaddr[MacAddrLen];
}DOT11_REASSOCIATION_IND;
typedef struct _DOT11_REASSOCIATION_RSP{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned char Status;
char CurrAPaddr[MacAddrLen];
}DOT11_REASSOCIATIIN_RSP;
// --- ---------- ---
typedef struct _DOT11_AUTHENTICATION_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
}DOT11_AUTHENTICATION_IND;
typedef struct _DOT11_REAUTHENTICATION_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
}DOT11_REAUTHENTICATION_IND;
typedef struct _DOT11_DEAUTHENTICATION_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned long tx_packets; // == transmited packets
unsigned long rx_packets; // == received packets
unsigned long tx_bytes; // == transmited bytes
unsigned long rx_bytes; // == received bytes
unsigned long Reason;
}DOT11_DEAUTHENTICATION_IND;
typedef struct _DOT11_DISASSOCIATION_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned long tx_packets; // == transmited packets
unsigned long rx_packets; // == received packets
unsigned long tx_bytes; // == transmited bytes
unsigned long rx_bytes; // == received bytes
unsigned long Reason;
}DOT11_DISASSOCIATION_IND;
#ifdef CONFIG_IEEE80211W
typedef struct _DOT11_SET_11W_Flags {
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char macAddr[MacAddrLen];
unsigned char isPMF;
}DOT11_SET_11W_Flags;
#endif /* CONFIG_IEEE80211W */
typedef struct _DOT11_DISCONNECT_REQ{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned short Reason;
char MACAddr[MacAddrLen];
}DOT11_DISCONNECT_REQ;
typedef struct _DOT11_SET_802DOT11{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char VariableType;
unsigned char VariableValue;
char MACAddr[MacAddrLen];
}DOT11_SET_802DOT11;
typedef struct _DOT11_SET_KEY{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned long KeyIndex;
unsigned long KeyLen;
unsigned char KeyType;
unsigned char EncType;
unsigned char MACAddr[MacAddrLen];
DOT11_KEY_RSC KeyRSC;
unsigned char KeyMaterial[64];
}DOT11_SET_KEY;
typedef struct _DOT11_SETPORT{
unsigned char EventId;
unsigned char PortStatus;
unsigned char PortType;
unsigned char MACAddr[MacAddrLen];
}DOT11_SETPORT;
typedef struct _DOT11_DELETE_KEY{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned char KeyType;
}DOT11_DELETE_KEY;
typedef struct _DOT11_SET_RSNIE{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned short Flag;
unsigned short RSNIELen;
char RSNIE[MAXRSNIELEN];
}DOT11_SET_RSNIE;
typedef struct _DOT11_GKEY_TSC{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char KeyTSC[8];
}DOT11_GKEY_TSC;
#ifdef RTL_WPA_CLIENT
typedef struct _DOT11_STA_QUERY_BSSID{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned long IsValid;
char Bssid[MacAddrLen];
}DOT11_STA_QUERY_BSSID;
typedef struct _DOT11_STA_QUERY_SSID{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned long IsValid;
char ssid[32];
int ssid_len;
}DOT11_STA_QUERY_SSID;
#endif
typedef struct _DOT11_MIC_FAILURE{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
}DOT11_MIC_FAILURE;
typedef struct _DOT11_EAPOL_START{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
}DOT11_EAPOL_START;
//2003-07-30 --------------
typedef struct _DOT11_SET_EXPIREDTIME{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char MACAddr[MacAddrLen];
unsigned long ExpireTime;
}DOT11_SET_EXPIREDTIME;
typedef struct _DOT11_QUERY_STATS{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char MACAddr[MacAddrLen];
unsigned long IsSuccess;
unsigned long tx_packets; // == transmited packets
unsigned long rx_packets; // == received packets
unsigned long tx_bytes; // == transmited bytes
unsigned long rx_bytes; // == received bytes
}DOT11_QUERY_STATS;
//-------------------------
typedef struct _DOT11_EAP_PACKET{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned short packet_len;
unsigned char packet[1550];
}DOT11_EAP_PACKET;
#ifdef WIFI_SIMPLE_CONFIG
typedef struct _DOT11_WSC_PIN_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char code[256];
} DOT11_WSC_PIN_IND;
typedef struct _DOT11_WSC_ASSOC_IND{
unsigned char EventId;
unsigned char IsMoreEvent;
char MACAddr[MacAddrLen];
unsigned short AssocIELen;
char AssocIE[PROBEIELEN];
unsigned char wscIE_included;
}DOT11_WSC_ASSOC_IND;
#endif
#define DOT11_AI_REQFI_CAPABILITIES 1
#define DOT11_AI_REQFI_LISTENINTERVAL 2
#define DOT11_AI_REQFI_CURRENTAPADDRESS 4
#define DOT11_AI_RESFI_CAPABILITIES 1
#define DOT11_AI_RESFI_STATUSCODE 2
#define DOT11_AI_RESFI_ASSOCIATIONID 4
typedef struct _DOT11_ASSOCIATION_INFORMATION
{
unsigned char EventId;
unsigned char IsMoreEvent;
unsigned char SupplicantAddress[MacAddrLen];
u_long Length;
u_short AvailableRequestFixedIEs;
struct _DOT11_AI_REQFI {
u_short Capabilities;
u_short ListenInterval;
char CurrentAPAddress[MacAddrLen];
} RequestFixedIEs;
u_long RequestIELength;
u_long OffsetRequestIEs;
u_short AvailableResponseFixedIEs;
struct _DOT11_AI_RESFI {
u_short Capabilities;
u_short StatusCode;
u_short AssociationId;
} ResponseFixedIEs;
u_long ResponseIELength;
u_long OffsetResponseIEs;
} DOT11_ASSOCIATION_INFORMATION, *PDOT11_ASSOCIATION_INFORMATION;
typedef struct _DOT11_INIT_QUEUE
{
unsigned char EventId;
unsigned char IsMoreEvent;
} DOT11_INIT_QUEUE, *PDOT11_INIT_QUEUE;
//------------------------------------------------------------
// For Key mapping key definition
//------------------------------------------------------------
//#define HW_CAM_CONFIG
#ifdef HW_CAM_CONFIG
struct rtl_priv_args
{
unsigned char arg_val;
unsigned char arg_name[16];
unsigned char arg_length;
};
#define PRIV_CMD_AP_KEYMAP_OPERATION 1
#define PRIV_CMD_AP_KEYMAP_MAC_ADDRESS 2
#define PRIV_CMD_AP_KEYMAP_KEY40 3
#define PRIV_CMD_AP_KEYMAP_KEY104 4
#define PRIV_CMD_AP_KEYMAP_KEY_INDEX 5
#define PRIV_CMD_AP_KEYMAP_KEY_TYPE 6
#define PRIV_CMD_AP_KEYMAP_KEY_VALID 7
static struct rtl_priv_args priv_cmd_keymap_args[] =
{
{ PRIV_CMD_AP_KEYMAP_OPERATION, "KMOP", 4 },
{ PRIV_CMD_AP_KEYMAP_MAC_ADDRESS, "KMAR", 4 },
{ PRIV_CMD_AP_KEYMAP_KEY40, "KMKEY40", 7 },
{ PRIV_CMD_AP_KEYMAP_KEY104, "KMKEY104", 8 },
{ PRIV_CMD_AP_KEYMAP_KEY_INDEX, "KMIDX", 5 },
{ PRIV_CMD_AP_KEYMAP_KEY_TYPE, "KMTYPE", 6 },
{ PRIV_CMD_AP_KEYMAP_KEY_VALID, "KMVALID", 7 }
};
#define KEYMAP_OPERATION_GET 0
#define KEYMAP_OPERATION_SET 1
#define KEYMAP_VALID_OFF 0
#define KEYMAP_VALID_ON 1
static struct rtl_priv_args rtl_priv_kmop_args[] =
{
{ KEYMAP_OPERATION_GET, "get", 3 },
{ KEYMAP_OPERATION_SET, "set", 3 }
};
#define WEP_MODE_OFF 0
#define WEP_MODE_ON_40 1
#define WEP_MODE_ON_104 2
static struct rtl_priv_args rtl_priv_wepmode_args[] =
{
{ WEP_MODE_OFF, "off", 3 },
{ WEP_MODE_ON_40, "wep40", 5 },
{ WEP_MODE_ON_104, "wep104", 6 }
};
static struct rtl_priv_args rtl_priv_kmvalid_args[] =
{
{ KEYMAP_VALID_ON, "on", 2 },
{ KEYMAP_VALID_OFF, "off", 3 }
};
#endif
//End of HW_CAM_CONFIG
//----------------------------------------------------------
/*-------------------- Function Definition ---------------*/
//use [ifdef] to exclude the following function definition
//in compile of dlisten
#include "1x_types.h"
#include "1x_common.h"
#ifdef RTL_WPA_CLIENT
#include "1x_supp_pae.h"
#endif
#define SIOCGIWIND 0x89ff
#define SIOCKEYMAP 0x89f9
#define SIOCGIWRTLSTAINFO 0x8B30
int lib1x_control_init();
int lib1x_control_STADisconnect(Global_Params *global, u_short reason);
int lib1x_control_RemovePTK(Global_Params *global, int keytype);
int lib1x_control_QueryRSC(Global_Params * global, OCTET_STRING * gRSC);
int lib1x_control_QuerySTA(Global_Params * global);
int lib1x_control_Query_All_Sta_Info(Dot1x_Authenticator * auth);
#ifdef RTL_WPA2
/*
event_id: DOT11_EVENT_ASSOCIATION_IND or DOT11_EVENT_REASSOCIATION_IND
*/
int lib1x_control_AssociationRsp(Global_Params * global, int result, int event_id);
#else
int lib1x_control_AssociationRsp(Global_Params * global, int result);
#endif
//int lib1x_control_SetRSNIE(Global_Params * global, int role);
int lib1x_control_RSNIE(Dot1x_Authenticator * auth, u_char flag);
int lib1x_control_SetPTK(Global_Params * global);
int lib1x_control_SetGTK(Global_Params * global);
int lib1x_control_SetPORT(Global_Params * global, u_char status);
int lib1x_control_SetExpiredTime(Global_Params * global, u_long ulExpireTime);
int lib1x_control_Set802dot1x(Global_Params * global, u_char var_type, u_char var_val);
int lib1x_control_InitQueue(Dot1x_Authenticator * auth);
int lib1x_control_KeyMapping(Global_Params * global, u_char operation, u_char keytype, u_char keyvalid);
int lib1x_control_IndicateMICFail(Dot1x_Authenticator * auth, u_char *mac);
int lib1x_control_Poll(Dot1x_Authenticator * auth);
#ifdef RTL_WPA_CLIENT
int lib1x_control_STA_QUERY_BSSID(Supp_Global * pGlobal);
int lib1x_control_STA_QUERY_SSID(Supp_Global * pGlobal, unsigned char *pSSID);
int lib1x_control_STA_SetPTK(Supp_Global * pGlobal);
int lib1x_control_STA_SetPORT(Supp_Global * pGlobal, u_char status);
int lib1x_control_STA_SetGTK(Supp_Global * pGlobal, u_char * pucKey, int iKeyId);
int lib1x_control_AuthDisconnect(Dot1x_Authenticator * auth, u_char *pucMacAddr, u_short reason);
#endif

View File

@ -0,0 +1,217 @@
#ifndef LIB1X_KMSM_H
#define LIB1X_KMSM_H
#include "1x_common.h"
#define TRUE 1
#define FALSE 0
#define SWAP(a, b) { tmp = b; b = a; a = tmp;}
#define NumGroupKey 4
#define REJECT_EAPOLSTART_COUNTER 3
typedef enum {SUCCESS = 0, ERROR_NULL_PSK = -1, ERROR_TIMEOUT = -2, ERROR_MIC_FAIL = -3,
ERROR_SET_PTK = -4, ERROR_NONEEQUL_REPLAYCOUNTER = -5,
ERROR_EQUALSMALLER_REPLAYCOUNTER = -6, ERROR_NONEQUAL_NONCE = -7, ERROR_AESKEYWRAP_MIC_FAIL = -8,
ERROR_LARGER_REPLAYCOUNTER = -9, ERROR_UNMATCHED_GROUPKEY_LEN = -10,
#ifdef RTL_WPA2_CLIENT
ERROR_NONEQUAL_RSNIE = -11, ERROR_RECV_4WAY_MESSAGE2_AGAIN = -12, ERROR_PMKID_PSK = -13, ERROR_PMKID_TLS = -14, ERROR_SECOND_RSNIE = -15} KMSM_ERROR_ID;
#else
ERROR_NONEQUAL_RSNIE = -11, ERROR_RECV_4WAY_MESSAGE2_AGAIN = -12} KMSM_ERROR_ID;
#endif
#define KM_STRERROR_NULL_PSK "NUUL Pairwise Share Key"
#define KM_STRERROR_TIMEOUT "Time Out"
#define KM_STRERROR_MIC_FAIL "MIC Failure"
#define KM_STRERROR_SET_PTK "Fail to set Pairwise Transient Key"
#define KM_STRERROR_NONEEQUL_REPLAYCOUNTER "Non Equal Replay "
#define KM_STRERROR_EQUALSMALLER_REPLAYCOUNTER "Equal/Smaller Replay "
#define KM_STRERROR_NONEQUAL_NONCE "Non Equal Nonce received in 3rd Message"
#define KM_STRERROR_AESKEYWRAP_MIC_FAIL "AES_WRAP MIC Fail"
#define KM_STRERROR_LARGER_REPLAYCOUNTER "Larger Replay "
#define KM_STRERROR_UNMATCHED_GROUPKEY_LEN "Invalid Group key length received"
#define KM_STRERROR_NONEQUAL_RSNIE "Non Equal RSN Information Element received"
typedef enum { akmsm_DEAUTHENTICATE, akmsm_DISCONNECTED, akmsm_INITIALIZE, \
akmsm_AUTHENTICATION, akmsm_INITPMK, akmsm_INITPSK, \
akmsm_PTKSTART, akmsm_PTKINITNEGOTIATING, \
akmsm_PTKINITDONE, akmsm_UPDATEKEYS, akmsm_MICFAILURE,\
akmsm_SETKEYS, akmsm_SETKEYSDONE, \
// Added states that are not in IEEE 802.11i/D3.0 8.5.6.1
// but appears in state machine diagram in Figure 53(p.113)
akmsm_DISCONNECT, akmsm_AUTHENTICATION2, aksm_INITPSK, aksm_PTKINITDONE, \
akmsm_INTEGRITYFAILURE, \
// Added states
akmsm_ERRORHANDLE} AUTH_PAIRWISEKEY_STATE;
typedef enum {gkmsm_REKEYNEGOTIATING, gkmsm_REKEYESTABLISHED, gkmsm_KEYERROR} AUTH_GROUPKEY_STATE;
typedef enum {
akmsm_EVENT_NoEvent,
akmsm_EVENT_AssociationRequest, akmsm_EVENT_ReAssociationRequest,
akmsm_EVENT_AuthenticationRequest, akmsm_EVENT_ReAuthenticationRequest,
akmsm_EVENT_AuthenticationSuccess,
akmsm_EVENT_Disconnect, akmsm_EVENT_DeauthenticationRequest, akmsm_EVENT_Init, akmsm_EVENT_Disassociate,
akmsm_EVENT_IntegrityFailure, akmsm_EVENT_EAPOLKeyRecvd,
akmsm_EVENT_TimeOut}Auth_Key_Manage_Event;
struct Global_Params_tag;
typedef struct Auth_GroupKeyManage_tag
{
// The Variables.
BOOLEAN GTKAuthenticator;
int GKeyDoneStations;
BOOLEAN GTKRekey;
BOOLEAN GInitAKeys;
BOOLEAN GInitDone;
BOOLEAN GUpdateStationKeys;
//int GNoStations; //== auth->NumOfSupplicant
BOOLEAN GkeyReady;
BOOLEAN GKeyFailure; //added by Emily
OCTET_STRING GNonce;
u_char GTK[NumGroupKey][GTK_LEN];
u_char GMK[GMK_LEN];
int GN;
int GM;
#ifdef CONFIG_IEEE80211W
unsigned char IGTK[2][IGTK_LEN];
int GN_igtk, GM_igtk;
union PN48 IGTK_PN;
#endif //CONFIG_IEEE80211W
u_long GRekeyCounts;
BOOLEAN GResetCounter;
}AGKeyManage_SM;
typedef struct Auth_PairwiseKeyManage_tag
{
// The machine state
AUTH_PAIRWISEKEY_STATE state;
AUTH_GROUPKEY_STATE gstate;
// The Variables.
//802.1x related variable
BOOLEAN eapStart;
u_long SessionTimeout;
u_long SessionTimeoutCounter;
u_long SessionTimeoutEnabled;
u_long IdleTimeout;
u_long IdleTimeoutCounter;
u_long IdleTimeoutEnabled;
u_long InterimTimeout;
u_long InterimTimeoutCounter;
u_long InterimTimeoutEnabled;
//-----------Event
BOOLEAN AuthenticationRequest;
BOOLEAN ReAuthenticationRequest;
BOOLEAN DeauthenticationRequest;
BOOLEAN Disconnect;
BOOLEAN Init;
BOOLEAN Pair;
BOOLEAN RadiusKeyAvailable;
BOOLEAN EAPOLKeyReceived;
BOOLEAN EAPOLKeySend; //added by Emily
BOOLEAN TimeoutEvt;
int TimeoutCtr;
//sc_yang
int TickCnt;
BOOLEAN L2Failure;
BOOLEAN MICVerified;
BOOLEAN IntegrityFailed;
BOOLEAN PInitAKeys;
//int ; //sc_yang
OCTET_STRING ANonce;
OCTET_STRING SNonce; //added by Emily
u_char PMK[PMK_LEN];
#ifdef RTL_WPA2
u_char PMKID[PMKID_LEN];
#endif
u_char PTK[PTK_LEN];
OCTET_STRING SuppInfoElement;
OCTET_STRING AuthInfoElement;
LARGE_INTEGER CurrentReplayCounter;
LARGE_INTEGER ReplayCounterStarted; // david+1-11-2007
u_short ErrorRsn;
struct Global_Params_tag *global;
BOOLEAN IfCalcMIC;
BOOLEAN bWaitForPacket;
int IgnoreEAPOLStartCounter;
//Abocom
/*
u_long SessionTimeout;
u_long IdleTimeout;
u_long InterimTimeout;
u_long SessionTimeoutCounter;
u_long IdleTimeoutCounter;
u_long InterimTimeoutCounter;
*/
}APKeyManage_SM;
int lib1x_akmsm_SendEAPOL_proc(Global_Params * global);
int lib1x_akmsm_ProcessEAPOL_proc(Global_Params * global);
int lib1x_akmsm_trans( Global_Params * global);
void lib1x_akmsm_execute( Global_Params * global);
void lib1x_akmsm_dump(Global_Params * global );
void lib1x_skmsm_execute( Global_Params * global);
int lib1x_skmsm_ProcessEAPOL_proc(Global_Params * global);
void lib1x_akmsm_EAPOLStart_Timer_proc(Dot1x_Authenticator * auth);
void lib1x_akmsm_Account_Timer_proc(Dot1x_Authenticator * auth);
int lib1x_akmsm_Disconnect( Global_Params * global);
int MIN(u_char * ucStr1, u_char * ucStr2, u_long ulLen);
void CalcPTK(u_char *addr1, u_char *addr2, u_char *nonce1,
u_char *nonce2, u_char * keyin, int keyinlen,
u_char * keyout, int keyoutlen
#ifdef CONFIG_IEEE80211W
,int use_sha256
#endif /* CONFIG_IEEE80211W */
);
void GenNonce(u_char * nonce, u_char * szRandom);
char * KM_STRERR(int err);
void KeyDump(char *fun, u_char *buf, int siz, char *comment);
OCTET32_INTEGER * INCOctet32_INTEGER(OCTET32_INTEGER * x);
int _tmain();
#endif //LIB1X_KMSM_H

View File

@ -0,0 +1,409 @@
#ifndef LIB1X_KMSM_EAPOLKEY_H
#define LIB1X_KMSM_EAPOLKEY_H
#include <string.h>
#ifdef _RTL_WPA_WINDOWS
typedef unsigned short u_short;
typedef unsigned char u_char;
typedef unsigned long u_long;
} OCTET_STRING, *POCTET_STRING, EAPOL_KEY;
#else
#include <sys/types.h>
#include "1x_kmsm_keydef.h"
#include "1x_types.h"
#endif
//original in 1x_ether.h and 1x_eapol.h
#define ETHER_HDRLEN 14
#define LIB1X_EAPOL_HDRLEN 4
#define ETHER_ADDRLEN 6
#ifdef CONFIG_IEEE80211W
#define GMK_EXPANSION_CONST "Group key expansion"
#define GMK_EXPANSION_CONST_SIZE 19
#define RANDOM_EXPANSION_CONST "Init Counter"
#define RANDOM_EXPANSION_CONST_SIZE 12
#define IGMK_EXPANSION_CONST "IGTK key expansion"
#define IGMK_EXPANSION_CONST_SIZE 18
#endif /* CONFIG_IEEE80211W */
//size of the field in information element
/*
#define PMK_LEN 32
#define PTK_LEN 64
#define PTK_LEN_TKIP 64
#define PTK_LEN_NO_TKIP 48 //for CCMP, WRAP, WEP
#define PTK_LEN_CCMP 48
#define PTK_LEN_WRAP 48
#define PTK_LEN_WEP 48
#define PTK_LEN_EAPOLMIC 16
#define PTK_LEN_EAPOLENC 16
#define GMK_LEN 32
#define GTK_LEN 32
#define GTK_LEN_TKIP 32 //32 for TKIP and 16 for CCMP, WRAP, WEP
#define GTK_LEN_NO_TKIP 16
#define GTK_LEN_CCMP 16
#define GTK_LEN_WRAP 16
#define GTK_LEN_WEP 16
#define INFO_ELEMENT_SIZE 128
#define MAX_EAPOLMSG_LEN 512
#define MAX_EAPOLKEYMSG_LEN MAX_EAPOLMSG_LEN - (ETHER_HDRLEN + LIB1X_EAPOL_HDRLEN)
#define EAPOLMSG_HDRLEN 95 //EAPOL-key payload length without KeyData
#define KEY_RC_LEN 8
#define KEY_NONCE_LEN 32
#define KEY_IV_LEN 16
#define KEY_RSC_LEN 8
#define KEY_ID_LEN 8
#define KEY_MIC_LEN 16
#define KEY_MATERIAL_LEN 2
#define DescTypePos 0
#define KeyInfoPos 1
#define KeyLenPos 3
#define ReplayCounterPos 5
#define KeyNoncePos 13
#define KeyIVPos 45
#define KeyRSCPos 61
#define KeyIDPos 69
#define KeyMICPos 77
#define KeyDataLenPos 93
#define KeyDataPos 95
*/
/*-----------------------------------------------------------------------------
Network and machine byte oder conversion
Macro definition
-------------------------------------------------------------------------------*/
// david --------------------------------------------------
// marked by chilong
//#ifdef AUTH_BIG_ENDIAN
// !!NOTES: chilong
// we define AUTH_BIG_ENDIAN instead of BIG_ENDIAN
// because kernel header in directory "[root_dir]/mipsel-linux/sys-include/netinet/in.h"
// has defined BIG_ENDIAN
#define long2net(l,c) (*((c) )=(unsigned char)(((l)>>24)&0xff), \
*((c)+1)=(unsigned char)(((l)>>16)&0xff), \
*((c)+2)=(unsigned char)(((l)>> 8)&0xff), \
*((c)+3)=(unsigned char)(((l) )&0xff))
#define net2long(c,l) (l =((unsigned long)(*((c) )))<<24, \
l|=((unsigned long)(*((c)+1)))<<16, \
l|=((unsigned long)(*((c)+2)))<< 8, \
l|=((unsigned long)(*((c)+3))))
#define short2net(s,c) (*((c))=(unsigned char)(((s)>> 8)&0xff), \
*((c)+1)=(unsigned char)(((s) )&0xff))
#define net2short(c,s) (s =((unsigned short)(*((c))))<< 8, \
s|=((unsigned short)(*((c)+1))))
//#else
//#define long2net(l,c) (*((unsigned long *)c) = l)
//#define net2long(c,l) (l = *((unsigned long *)c))
//#define short2net(s,c) (*((unsigned short *)c) = s)
//#define net2short(c,s) (s = *((unsigned short *)c))
//#endif
//------------------------------------------------------
//-------------------------------------------------
#define lint2net(l,c) (long2net((l).HighPart, c) , long2net((l).LowPart, c+4))
#define net2lint(c,l) (net2long(c, (l).HighPart) , net2long(c+4, (l).LowPart))
/*-----------------------------------------------------------------------------
LargeInteger
Inline Function definition
Macro definition
-------------------------------------------------------------------------------*/
#define LargeIntegerOverflow(x) ((x).field.HighPart == 0xffffffff) && \
((x).field.LowPart == 0xffffffff)
#define LargeIntegerZero(x) memset(&(x).charData, 0, 8);
/*-----------------------------------------------------------------------------
Octet16Integer
Inline Function definition
Macro definition
-------------------------------------------------------------------------------*/
#define Octet16IntegerOverflow(x) LargeIntegerOverflow((x).field.HighPart) && \
LargeIntegerOverflow((x).field.LowPart)
#define Octet16IntegerZero(x) memset(&(x).charData, 0, 16);
/*-----------------------------------------------------------------------------
EAPOLKey field process
Inline Function definition
Macro definition
-------------------------------------------------------------------------------*/
inline
OCTET_STRING SubStr(OCTET_STRING f, u_short s,u_short l);
#define SetSubStr(f,a,l) memcpy((f).Octet+(l), (a).Octet, (a).Length)
#define GetKeyInfo0(f, mask) ( ((f).Octet[KeyInfoPos + 1] & (mask)) ? 1 :0)
#define SetKeyInfo0(f,mask,b) ( (f).Octet[KeyInfoPos + 1] = ((f).Octet[KeyInfoPos + 1] & ~(mask)) | ( (b)?(mask):0x0) )
#define GetKeyInfo1(f, mask) ( ((f).Octet[KeyInfoPos] & (mask)) ? 1 :0)
#define SetKeyInfo1(f,mask,b) ( (f).Octet[KeyInfoPos] = ((f).Octet[KeyInfoPos] & ~(mask)) | ( (b)?(mask):0x0) )
// EAPOLKey
#define Message_DescType(f) ((f).Octet[DescTypePos])
#define Message_setDescType(f, type) ((f).Octet[DescTypePos] = (type))
// Key Information Filed
#define Message_KeyDescVer(f) ((f).Octet[KeyInfoPos+1] & 0x07)//(f.Octet[KeyInfoPos+1] & 0x01) | (f.Octet[KeyInfoPos+1] & 0x02) <<1 | (f.Octet[KeyInfoPos+1] & 0x04) <<2
#define Message_setKeyDescVer(f, v) ((f).Octet[KeyInfoPos+1] &= 0xf8) , (f).Octet[KeyInfoPos+1] |= ((v) & 0x07)//(f.Octet[KeyInfoPos+1] |= ((v&0x01)<<7 | (v&0x02)<<6 | (v&0x04)<<5) )
#define Message_KeyType(f) GetKeyInfo0(f,0x08)
#define Message_setKeyType(f, b) SetKeyInfo0(f,0x08,b)
#define Message_KeyIndex(f) (((f).Octet[KeyInfoPos+1] & 0x30) >> 4)//(f.Octet[KeyInfoPos+1] & 0x20) | (f.Octet[KeyInfoPos+1] & 0x10) <<1
#define Message_setKeyIndex(f, v) ((f).Octet[KeyInfoPos+1] &= 0xcf), (f).Octet[KeyInfoPos+1] |= (((v)<<4) & 0x07)//(f.Octet[KeyInfoPos+1] |= ( (v&0x01)<<5 | (v&0x02)<<4) )
#define Message_Install(f) GetKeyInfo0(f,0x40)
#define Message_setInstall(f, b) SetKeyInfo0(f,0x40,b)
#define Message_KeyAck(f) GetKeyInfo0(f,0x80)
#define Message_setKeyAck(f, b) SetKeyInfo0(f,0x80,b)
#define Message_KeyMIC(f) GetKeyInfo1(f,0x01)
#define Message_setKeyMIC(f, b) SetKeyInfo1(f,0x01,b)
#define Message_Secure(f) GetKeyInfo1(f,0x02)
#define Message_setSecure(f, b) SetKeyInfo1(f,0x02,b)
#define Message_Error(f) GetKeyInfo1(f,0x04)
#define Message_setError(f, b) SetKeyInfo1(f,0x04,b)
#define Message_Request(f) GetKeyInfo1(f,0x08)
#define Message_setRequest(f, b) SetKeyInfo1(f,0x08,b)
#define Message_Reserved(f) ((f).Octet[KeyInfoPos] & 0xf0)
#define Message_setReserved(f, v) ((f).Octet[KeyInfoPos] |= ((v)<<4&0xff))
#define Message_KeyLength(f) ((u_short)((f).Octet[KeyLenPos] <<8) + (u_short)((f).Octet[KeyLenPos+1]))
#define Message_setKeyLength(f, v) ((f).Octet[KeyLenPos] = ((v)&0xff00) >>8 , (f).Octet[KeyLenPos+1] = ((v)&0x00ff))
/* Replay Counter process function */
#define DEFAULT_KEY_REPLAY_COUNTER_LONG 0xffffffff
#define Message_DefaultReplayCounter(li) ((li.field.HighPart == DEFAULT_KEY_REPLAY_COUNTER_LONG) && (li.field.LowPart == DEFAULT_KEY_REPLAY_COUNTER_LONG) ) ?1:0
#define Message_ReplayCounter(f) SubStr(f, ReplayCounterPos, KEY_RC_LEN)
#define Message_CopyReplayCounter(f1, f2) memcpy(f1.Octet + ReplayCounterPos, f2.Octet + ReplayCounterPos, KEY_RC_LEN)
void Message_ReplayCounter_OC2LI(OCTET_STRING f, LARGE_INTEGER * li);
void ReplayCounter_OC2LI(OCTET_STRING f, LARGE_INTEGER * li);
int Message_EqualReplayCounter(LARGE_INTEGER li1, OCTET_STRING f);
int Message_SmallerEqualReplayCounter(LARGE_INTEGER li1, OCTET_STRING f);
int Message_LargerReplayCounter(LARGE_INTEGER li1, OCTET_STRING f);
void Message_setReplayCounter(OCTET_STRING f, u_long h, u_long l);
//#define SetNonce(x,y) memcpy(x.Octet, y.charData, 32);
void SetNonce(OCTET_STRING osDst, OCTET32_INTEGER oc32Counter);
#define Message_KeyNonce(f) SubStr((f),KeyNoncePos,KEY_NONCE_LEN)
#define Message_setKeyNonce(f, v) SetSubStr((f), (v), KeyNoncePos)
#define Message_EqualKeyNonce(f1, f2) (memcmp((f1).Octet + KeyNoncePos, (f2).Octet, KEY_NONCE_LEN)? 0:1)
#define Message_KeyIV(f) Substr((f), KeyIVPos, KEY_IV_LEN)
#define Message_setKeyIV(f, v) SetSubStr((f), (v), KeyIVPos)
#define Message_KeyRSC(f) Substr((f), KeyRSCPos, KEY_RSC_LEN)
#define Message_setKeyRSC(f, v) SetSubStr((f), (v), KeyRSCPos)
#define Message_KeyID(f) Substr((f), KeyIDPos, KEY_ID_LEN)
#define Message_setKeyID(f, v) SetSubStr((f), (v), KeyIDPos)
#define Message_MIC(f) Substr((f), KeyMICPos, KEY_MIC_LEN)
#define Message_setMIC(f, v) SetSubStr((f), (v), KeyMICPos)
#define Message_clearMIC(f) memset((f).Octet+KeyMICPos, 0, KEY_MIC_LEN)
#define Message_KeyDataLength(f) ((u_short)((f).Octet[KeyDataLenPos] <<8) + (u_short)((f).Octet[KeyDataLenPos+1]))
#define Message_setKeyDataLength(f, v) ((f).Octet[KeyDataLenPos] = ((v)&0xff00) >>8 , (f).Octet[KeyDataLenPos+1] = ((v)&0x00ff))
#define Message_KeyData(f, l) SubStr((f), KeyDataPos, (l))
#define Message_setKeyData(f, v) SetSubStr((f), (v), KeyDataPos);
#define Message_EqualRSNIE(f1 , f2, l) (memcmp((f1).Octet, (f2).Octet, (l)) ? 0:1)
#define Message_ReturnKeyDataLength(f) ((f).Length - (ETHER_HDRLEN + LIB1X_EAPOL_HDRLEN + EAPOLMSG_HDRLEN))
typedef union _KeyInfo
{
u_short shortData;
u_char charData[2];
struct
{
u_short KeyDescVersion:3;
u_short KeyType:1;
u_short KeyIndex:2;
u_short Install:1;
u_short KeyAck:1;
u_short KeyMIC:1;
u_short Secure:1;
u_short Error:1;
u_short Request:1;
u_short Reserved:4;
}field;
}KeyInfo;
#define KeyInfo_KeyDescVersion(f) ( ((KeyInfo *)((f).Octet)) ->field.KeyDescVersion)
#define KeyInfo_KeyType(f) ( ((KeyInfo *)((f).Octet)) ->field.KeyType)
#define KeyInfo_KeyIndex(f) ( ((KeyInfo *)((f).Octet)) ->field.KeyIndex)
#define KeyInfo_Install(f) ( ((KeyInfo *)((f).Octet)) ->field.Install)
#define KeyInfo_KeyAck(f) ( ((KeyInfo *)((f).Octet)) ->field.KeyAck)
#define KeyInfo_KeyMic(f) ( ((KeyInfo *)((f).Octet)) ->field.KeyMic)
#define KeyInfo_Secure(f) ( ((KeyInfo *)((f).Octet)) ->field.Secure)
#define KeyInfo_Error(f) ( ((KeyInfo *)((f).Octet)) ->field.Error)
#define KeyInfo_Request(f) ( ((KeyInfo *)((f).Octet)) ->field.Request)
#define KeyInfo_Reserved(f) ( ((KeyInfo *)((f).Octet)) ->field.Reserved)
struct _LIB1X_EAPOL_KEY
{
u_char key_desc_ver;
//KeyInfo key_info;
u_char key_info[2];
u_char key_len[sizeof(u_short)];
u_char key_replay_counter[KEY_RC_LEN];
u_char key_nounce[KEY_NONCE_LEN];
u_char key_iv[KEY_IV_LEN];
u_char key_rsc[KEY_RSC_LEN];
u_char key_id[KEY_ID_LEN];
u_char key_mic[KEY_MIC_LEN];
u_char key_data_len[KEY_MATERIAL_LEN];
u_char *key_data;
};
typedef struct _LIB1X_EAPOL_KEY lib1x_eapol_key;
//---------------------------------------------------------------------
// Definition for 1x_kmsm_eapolkey.c
//---------------------------------------------------------------------
void INCLargeInteger(
LARGE_INTEGER * x);
void ReplayCounter_LI2OC(
OCTET_STRING f,
LARGE_INTEGER * li);
void EncGTK(
Global_Params * global,
u_char *kek,
int keklen,
u_char *key,
int keylen,
u_char *out,
u_short *outlen);
int CheckMIC(
OCTET_STRING EAPOLMsgRecvd,
u_char *key,
int keylen);
#ifdef RTL_WPA2
void CalcPMKID(
char* pmkid,
char* pmk,
char* aa,
char* spa
#ifdef CONFIG_IEEE80211W
,int use_sha256
#endif /* CONFIG_IEEE80211W */
);
#endif
void CalcMIC(
OCTET_STRING EAPOLMsgSend,
int algo,
u_char *key,
int keylen);
void CalcGTK(
u_char *addr,
u_char *nonce,
u_char * keyin,
int keyinlen,
u_char * keyout,
int keyoutlen
#ifdef CONFIG_IEEE80211W
,u_char * label
#endif /* CONFIG_IEEE80211W */
);
int DecGTK(
OCTET_STRING EAPOLMsgRecvd,
u_char *kek,
int keklen,
int keylen,
u_char *kout,
int kout_len);
#ifdef RTL_WPA2
void SetEAPOL_KEYIV(
OCTET_STRING ocDst,
OCTET32_INTEGER oc32Counter);
#endif
//------------------------------------------------------------------------
// Definition file for 1x_kmsm_hmac.c
//------------------------------------------------------------------------
void hmac_sha(
unsigned char* k, /* secret key */
int lk, /* length of the key in bytes */
unsigned char* d, /* data */
int ld, /* length of data in bytes */
unsigned char* out, /* output buffer, at least "t" bytes */
int t
);
void hmac_sha1(
unsigned char *text,
int text_len,
unsigned char *key,
int key_len,
unsigned char *digest);
void
hmac_md5(
unsigned char *text,
int text_len,
unsigned char *key,
int key_len,
void * digest);
//------------------------------------------------------------------------
// Definition file for 1x_kmsm_prf.c
//------------------------------------------------------------------------
void i_PRF(
unsigned char* secret,
int secret_len,
unsigned char* prefix,
int prefix_len,
unsigned char* random,
int random_len,
unsigned char* digest, // caller digest to be filled in
int digest_len // in byte
);
//------------------------------------------------------------------------
// Definition file for 1x_kmsm_aes.c
//------------------------------------------------------------------------
typedef unsigned char u08b; /* an 8 bit unsigned character type */
typedef unsigned short u16b; /* a 16 bit unsigned integer type */
typedef unsigned long u32b; /* a 32 bit unsigned integer type */
void AES_WRAP(
u08b * plain,
int plain_len,
u08b * iv,
int iv_len,
u08b * kek,
int kek_len,
u08b *cipher,
u16b *cipher_len);
void AES_UnWRAP(
u08b * cipher,
int cipher_len,
u08b * kek,
int kek_len,
u08b * plain,
int plain_len);
#endif

View File

@ -0,0 +1,51 @@
#define PMK_LEN 32
#ifdef RTL_WPA2
#define PMKID_LEN 16
#endif
#define PTK_LEN 64
#define PTK_LEN_TKIP 64
#define PTK_LEN_NO_TKIP 48 //for CCMP, WRAP, WEP
#define PTK_LEN_CCMP 48
#define PTK_LEN_WRAP 48
#define PTK_LEN_WEP 48
#define PTK_LEN_EAPOLMIC 16
#define PTK_LEN_EAPOLENC 16
#define GMK_LEN 32
#define GTK_LEN 32
#define GTK_LEN_TKIP 32 //32 for TKIP and 16 for CCMP, WRAP, WEP
#define GTK_LEN_NO_TKIP 16
#define GTK_LEN_CCMP 16
#define GTK_LEN_WRAP 16
#define GTK_LEN_WEP 16
#ifdef CONFIG_IEEE80211W
#define IGTK_LEN 16
#endif /* CONFIG_IEEE80211W */
#define INFO_ELEMENT_SIZE 128
#define MAX_EAPOLMSG_LEN 512
#define MAX_EAPOLKEYMSG_LEN MAX_EAPOLMSG_LEN - (ETHER_HDRLEN + LIB1X_EAPOL_HDRLEN)
#define EAPOLMSG_HDRLEN 95 //EAPOL-key payload length without KeyData
#define KEY_RC_LEN 8
#define KEY_NONCE_LEN 32
#define KEY_IV_LEN 16
#define KEY_RSC_LEN 8
#define KEY_ID_LEN 8
#define KEY_MIC_LEN 16
#define KEY_MATERIAL_LEN 2
#define DescTypePos 0
#define KeyInfoPos 1
#define KeyLenPos 3
#define ReplayCounterPos 5
#define KeyNoncePos 13
#define KeyIVPos 45
#define KeyRSCPos 61
#define KeyIDPos 69
#define KeyMICPos 77
#define KeyDataLenPos 93
#define KeyDataPos 95

View File

@ -0,0 +1,35 @@
#ifndef LIB1X_KRC_SM_H
#define LIB1X_KRC_SM_H
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_krc_sm.h
// Programmer : Arunesh Mishra
// The Key Receive State Machine
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
typedef struct Krc_SM_tag
{
KRC_SM state;
BOOLEAN rxKey;
} Krc_SM;
void lib1x_krcsm_processKey();
void lib1x_krcsm_init( Krc_SM * krc_sm );
void lib1x_trans_krcsm( Global_Params * global, Krc_SM * krc_sm );
#endif

View File

@ -0,0 +1,42 @@
#ifndef LIB1x_KXSM_H
#define LIB1x_KXSM_H
#include "1x_types.h"
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_kxsm.h
// Programmer : Arunesh Mishra
//
// H file Key Transmit State Machine.
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
struct Auth_Pae_tag;
struct Global_Params_tag;
typedef struct Auth_keyxmitSM_tag
{
AUTH_KEYSM state;
BOOLEAN keyAvailable;
// Constants
BOOLEAN keyTxEnabled;
} Auth_KeyxmitSM;
void lib1x_trans_kxsm( struct Auth_Pae_tag * auth_pae, struct Global_Params_tag * global, Auth_KeyxmitSM * key_sm );
void lib1x_kxsm_init( Auth_KeyxmitSM * key_sm );
void lib1x_kxsm_key_transmit( struct Auth_Pae_tag * auth_pae, struct Global_Params_tag * global, Auth_KeyxmitSM * key_sm );
void lib1x_authxmitsm_txKey( struct Auth_Pae_tag * auth_pae, int currentId);
#endif

View File

@ -0,0 +1,181 @@
#ifndef LIB1x_LIST_H
#define LIB1x_LIST_H
//----------------------------------------------------------------
// list from Linux kernel List /include/linux/list.h
//----------------------------------------------------------------
// #include <linux/prefetch.h>
static inline void prefetch(const void *x) {;}
/*
* Simple doubly linked list implementation.
*
* Some of the internal functions ("__xxx") are useful when
* manipulating whole lists rather than single entries, as
* sometimes we already know the next/prev entries and we can
* generate better code by using them directly rather than
* using the generic single-entry routines.
*/
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static __inline__ void __list_add(struct list_head * new,
struct list_head * prev,
struct list_head * next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
/**
* list_add - add a new entry
* @new: new entry to be added
* @head: list head to add it after
*
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
static __inline__ void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
/**
* list_add_tail - add a new entry
* @new: new entry to be added
* @head: list head to add it before
*
* Insert a new entry before the specified head.
* This is useful for implementing queues.
*/
static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
/*
* Delete a list entry by making the prev/next entries
* point to each other.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static __inline__ void __list_del(struct list_head * prev,
struct list_head * next)
{
next->prev = prev;
prev->next = next;
}
/**
* list_del - deletes entry from list.
* @entry: the element to delete from the list.
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
*/
static __inline__ void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
}
/**
* list_del_init - deletes entry from list and reinitialize it.
* @entry: the element to delete from the list.
*/
static __inline__ void list_del_init(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
INIT_LIST_HEAD(entry);
}
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
static __inline__ int list_empty(struct list_head *head)
{
return head->next == head;
}
/**
* list_splice - join two lists
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
static __inline__ void list_splice(struct list_head *list, struct list_head *head)
{
struct list_head *first = list->next;
if (first != list) {
struct list_head *last = list->prev;
struct list_head *at = head->next;
first->prev = head;
head->next = first;
last->next = at;
at->prev = last;
}
}
/**
* list_entry - get the struct for this entry
* @ptr: the &struct list_head pointer.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
/**
* list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next, prefetch(pos->next); pos != (head); \
pos = pos->next, prefetch(pos->next))
/**
* list_for_each_safe - iterate over a list safe against removal of list entry
* @pos: the &struct list_head to use as a loop counter.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/**
* list_for_each_prev - iterate over a list in reverse order
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
*/
#define list_for_each_prev(pos, head) \
for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
pos = pos->prev, prefetch(pos->prev))
#endif /* LIB1x_LIST_H */

View File

@ -0,0 +1,182 @@
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_nal.h
// Programmer : Arunesh Mishra
// Declarations for the Network Abstraction Layer
//
//
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//
//--------------------------------------------------
#ifndef LIB1X_NAL_H
#define LIB1X_NAL_H
#include <sys/types.h>
#ifdef _ON_RTL8181_TARGET
//#include <pcap.h>
#else
//#include <pcap/pcap.h>
#endif
#include "libnet.h"
//#include "/usr/include/libnet.h"
#include "1x_types.h"
#include "1x_common.h"
#include "1x_ethernet.h"
#include "1x_auth_pae.h"
#include <sys/socket.h>
#include <features.h> /* for the glibc version number */
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
#include <net/ethernet.h> /* the L2 protocols */
#else
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h> /* The L2 protocols */
#endif
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
// The address types
#define LIB1X_NAL_MACADDR 1
#define LIB1X_NAL_IPADDR 2
// Interface types.
#define LIB1X_NAL_IT_ETHLAN 1
#define LIB1X_NAL_IT_WLAN 2
#define LIB1X_MAXDEVLEN IFNAMSIZ + 10 /* be safe */
//#define LIB1X_MAXEAPLEN 5500
#define LIB1X_MAXEAPLEN 1600 //sc_yang
// This structure defines an "address". This could
// be an IP address or a MAC address, thus doing it
// this way gives us a "generic" interface.
struct lib1x_nal_addr
{
unsigned char * addr;
int len;
int addr_type;
};
// Abstracts the notion of an interface, which could be a socket
// or an actual device
struct lib1x_nal_intdev
{
unsigned char * interface;
int type;
};
/* Generic packet struct .. passed to the handler */
struct lib1x_packet
{
u_char *data;
int caplen;
};
// We shall use the Berkeley Packet Capture Utility.
#define LIB1X_LSTNR_PROMISCMODE 1
#define LIB1X_LSTNR_SNAPLEN 2500 // I guess we need the entire packet.
#define LIB1X_LSTNR_RDTIMEOUT 1000 // Just using what the tcpdump guys used !
#define LIB1X_IT_PKTSOCK 1
#define LIB1X_IT_UDPSOCK 2
#define LIB1X_IT_CTLSOCK 3
#define LIB1X_IT_UDPSOCK_AUTH 1
#define LIB1X_IT_UDPSOCK_ACCT 2
#if 0 //sc_yang
void lib1x_nal_pcappkt_handler( u_char * lib1x_data, const struct pcap_pkthdr * packet_header, const u_char * the_packet );
struct lib1x_nal_intfdesc;
typedef void lib1x_nal_genpkt_handler( Global_Params * , struct lib1x_nal_intfdesc * , struct lib1x_packet * );
#endif
// Interface descriptor
struct lib1x_nal_intfdesc
{
//1. The listener datastructures
#if 0 //sc_yang
pcap_t * pcap_desc;
u_char p_errbuf[PCAP_ERRBUF_SIZE + 1];
#endif
BOOLEAN promisc_mode;
int snaplen;
int read_timeout;
int pf_sock; // socket : PF_PACKET since libpcap needs to get discarded
// struct lib1x_nal_intdev * device;
u_char device[ LIB1X_MAXDEVLEN + 1];
#if 0
lib1x_nal_genpkt_handler * packet_handler; /* not using currently, it is dynamic */
#endif
struct sockaddr_ll sock_device;
u_char * packet_buffer;
struct lib1x_packet packet;
//2. The Xmitter datastructures
struct libnet_link_int * libnet_desc;
u_char l_errbuf[LIBNET_ERRBUF_SIZE];
//3. general ..
u_char ouraddr[ ETHER_ADDRLEN ];
u_char inttype; /* interface type, packet socket or udp socket */
/*4. If we are having a UDP authentication socket */
int udpsock;
#ifdef CONFIG_RTL8196C_AP_HCM
int inband_channel;
unsigned int if_index;
unsigned char host_mac[13];
#endif
struct sockaddr_in *radsvraddr;
/*5. If we are having a UDP accouting socket */
int acctsock;
struct sockaddr_in *acctsvraddr;
};
struct lib1x_nal_intfdesc * lib1x_nal_initialize( u_char * intdev , u_char * ouraddr, u_char inttype);
BOOLEAN lib1x_nal_send( struct lib1x_nal_intfdesc * desc, char * packet , int size);
// david
//void lib1x_nal_receivepoll( Dot1x_Authenticator * auth, struct lib1x_nal_intfdesc * desc , lib1x_nal_genpkt_handler * pkt_handler, u_char * info);
//void lib1x_nal_receivefifo(Dot1x_Authenticator * auth);
#if 0
int lib1x_nal_receivepoll( Dot1x_Authenticator * auth, struct lib1x_nal_intfdesc * desc , lib1x_nal_genpkt_handler * pkt_handler, u_char * info);
int lib1x_nal_receivefifo(Dot1x_Authenticator * auth);
#endif
int lib1x_nal_receive(Dot1x_Authenticator * auth);
void lib1x_nal_close( struct lib1x_nal_intfdesc * desc );
//pcap_t * lib1x_nal_setup_pcap( struct lib1x_nal_intfdesc * nd );
int lib1x_nal_connect( struct lib1x_nal_intfdesc * desc, /*u_short udp_ourport,*/ struct sockaddr_in *svraddr , int addrlen, int udpsock_type);
#endif

View File

@ -0,0 +1,21 @@
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : common.h
// Programmer : Arunesh Mishra
//
// Contains all common declarations and definitions.
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
//--------------------------------------------------
#ifndef LIB1X_PARSER_H
#define LIB1X_PARSER_H
void lib1x_parsePrint( FILE * fdesc, Auth_Pae * auth_pae, struct lib1x_packet * spkt )
#endif

View File

@ -0,0 +1,58 @@
//#ifndef 1X_PKT_LISTENER_H
//#define 1X_PKT_LISTENER_H
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_pkt_listener.h
// Programmer : Arunesh Mishra
//
// Contains code for packet listening.
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
// We shall use the Berkeley Packet Capture Utility.
#include <sys/types.h>
#include <pcap.h>
#include "1x_types.h"
#include "1x_common.h"
#define LIB1X_LSTNR_PROMISCMODE 1
#define LIB1X_LSTNR_SNAPLEN 1500 // I guess we need the entire packet.
#define LIB1X_LSTNR_RDTIMEOUT 1000 // Just using what the tcpdump guys used !
typedef struct PKT_LSTNR_tag
{
pcap_t * pkt_desc;
u_char error_buf[PCAP_ERRBUF_SIZE + 1];
BOOLEAN promisc_mode;
int snaplen;
int read_timeout;
char *device;
pcap_handler packet_handler;
Global_Params * global;
} PKT_LSTNR;
void lib1x_pktlst_packet_handler( u_char * lib1x_data , const struct pcap_pkthdr * packet_header,
const u_char * the_packet);
PKT_LSTNR * lib1x_pktlst_init( char * device , Global_Params * global );
void lib1x_pktlst_process( PKT_LSTNR * listener );
//#endif

View File

@ -0,0 +1,33 @@
#ifndef 1X_PKT_XMIT_H
#define 1X_PKT_XMIT_H
#include <libnet.h>
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_pkt_xmit.h
// Programmer : Arunesh Mishra
// Structure for libnet.
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
typedef struct PKT_XMIT_tag
{
struct libnet_link_int * network;
u_char *device;
u_char errbuf[LIBNET_ERRBUF_SIZE];
Global_Params * global;
} PKT_XMIT;
#endif

View File

@ -0,0 +1,50 @@
#ifndef LIB1x_PTSM_H
#define LIB1x_PTSM_H
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_ptsm.h
// Programmer : Arunesh Mishra
//
// Port timers state machine H file.
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
struct lib1x_ptsm
{
int authWhile;
// authwhile is a timer used by supp to wait for a resp from
// authenticator before timing out.
int aWhile;
// timer used by backend auth state machine.
int heldWhile;
//timer for supp - during which it does not attempt to authenticate
int quietWhile;
// timer used by auth sm during which it does not acquire a supp.
int reAuthWhen;
// reauthentication timer state machine = reAuthPeriod.
int startWhen;
// timer for supp - EAPOL start message
int txWhen;
// used by auth sm
};
void lib1x_ptsm_alarm( int signum );
void lib1x_ptsm_initialize( Global_Params * global, struct lib1x_ptsm * ptsm );
void lib1x_ptsm_timer(Dot1x_Authenticator * auth);
typedef struct lib1x_ptsm PT_SM;
#endif

View File

@ -0,0 +1,310 @@
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_radius.h
// Programmer : Arunesh Mishra
//
// BASIC RADIUS PROXY
//
//
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//
//
//--------------------------------------------------
#ifndef LIB1X_RADIUS_H
#define LIB1X_RADIUS_H
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "1x_nal.h"
#define LIB1X_ETH_IP 0x0800 /* Internet Protocol packet */
#define LIB1X_RAD_ACCREQ 1 // Access Request
#define LIB1X_RAD_ACCACT 2 // Access Accept
#define LIB1X_RAD_ACCREJ 3 // Access Reject
#define LIB1X_RAD_ACCCHL 11 // Access Challenge
#define LIB1X_RAD_ACCTREQ 4 // Account Request
#define LIB1X_RAD_ACCTRSP 5 // Account Respond
#if 0 // move define to makefile
#define LIB1X_LIL_ENDIAN
#endif
#define LIB1X_IPHDRLEN 20 // Assume for now TODO
#define LIB1X_UDPHDRLEN 8
#define LIB1X_RADHDRLEN 20 // RADIUS Header length
#define LIB1X_RADATTRLEN 2 // length of attr field without data part
/* RADIUS attribute definitions. Also from RFC 2138 */
#define LIB1X_RAD_USER_NAME 1
#define LIB1X_RAD_PASSWORD 2
#define LIB1X_RAD_NAS_IP_ADDRESS 4
#define LIB1X_RAD_NAS_PORT 5
#define LIB1X_RAD_SERVICE_TYPE 6
#define LIB1X_RAD_FRAMED_MTU 12
#define LIB1X_RAD_REPLY_MESSAGE 18
#define LIB1X_RAD_STATE 24
#define LIB1X_RAD_VENDOR_SPECIFIC 26
#define LIB1X_RAD_SESSION_TIMEOUT 27
#define LIB1X_RAD_IDLE_TIMEOUT 28
#define LIB1X_RAD_CALLED_STID 30
#define LIB1X_RAD_CALLING_STID 31
#define LIB1X_RAD_NAS_IDENTIFIER 32
#define LIB1X_RAD_NAS_PORTTYPE 61
#define LIB1X_RAD_CONNECTINFO 77
#define LIB1X_RAD_EAP_MESSAGE 79 // eap message .. from RFC 2869
#define LIB1X_RAD_MESS_AUTH 80 // Message Authenticator
#define LIB1X_RAD_NAS_PORT_ID 83
//Accounting related
#define LIB1X_RAD_ACCT_STATUS_TYPE 40
#define LIB1X_RAD_ACCT_DELAY_TIME 41
#define LIB1X_RAD_ACCT_INPUT_OCTETS 42
#define LIB1X_RAD_ACCT_OUTPUT_OCTETS 43
#define LIB1X_RAD_ACCT_SESSION_ID 44
#define LIB1X_RAD_ACCT_AUTHENTIC 45
#define LIB1X_RAD_ACCT_SESSION_TIME 46
#define LIB1X_RAD_ACCT_INPUT_PACKETS 47
#define LIB1X_RAD_ACCT_OUTPUT_PACKETS 48
#define LIB1X_RAD_ACCT_TERMINATE_CAUSE 49
#define LIB1X_RAD_ACCT_INPUT_GIGAWORDS 52
#define LIB1X_RAD_ACCT_OUTPUT_GIGAWORDS 53
#define LIB1X_RAD_ACCT_INTERIM_TIMEOUT 85
/* Radius vendor specific definition from RFC 2548
Microsoft Vendor-specific RADIUS attributes */
#define LIB1X_RADVENDOR_MS 311 // 0x00000137
#define LIB1X_RADVENDOR_MS_MPPE_SEND_KEY 16
#define LIB1X_RADVENDOR_MS_MPPE_RECV_KEY 17
#define LIB1X_RADVENDOR_MS_MPPE_ENCRYPTION_POLICY 7
#define LIB1X_RADVENDOR_MS_MPPE_ENCRYPTION_TYPES 8
/* Accounting related Attribute */
#define LIB1X_RADACCT_STATUS_TYPE_START 1
#define LIB1X_RADACCT_STATUS_TYPE_STOP 2
#define LIB1X_RADACCT_STATUS_TYPE_INTERIM_UPDATE 3
#define LIB1X_RADACCT_STATUS_TYPE_ACCOUNTING_ON 7
#define LIB1X_RADACCT_STATUS_TYPE_ACCOUNTING_OFF 8
#define LIB1X_RADACCT_AUTHENTIC_RADIUS 1
#define LIB1X_RADACCT_AUTHENTIC_LOCAL 2
#define LIB1X_RADACCT_AUTHENTIC_REMOTE 3
#define LIB1X_RADACCT_TERMINATE_CAUSE_USER_REQUEST 1
#define LIB1X_RADACCT_TERMINATE_CAUSE_LOST_CARRIER 2
#define LIB1X_RADACCT_TERMINATE_CAUSE_LOST_SERVICE 3
#define LIB1X_RADACCT_TERMINATE_CAUSE_IDLE_TIMEOUT 4
#define LIB1X_RADACCT_TERMINATE_CAUSE_SESSION_TIMEOUT 5
#define LIB1X_RADACCT_TERMINATE_CAUSE_ADMIN_RESET 6
#define LIB1X_RADACCT_TERMINATE_CAUSE_ADMIN_REBOOT 7
#define LIB1X_RADACCT_TERMINATE_CAUSE_PORT_ERROR 8
#define LIB1X_RADACCT_TERMINATE_CAUSE_NAS_ERROR 9
#define LIB1X_RADACCT_TERMINATE_CAUSE_NAS_REQUEST 10
#define LIB1X_RADACCT_TERMINATE_CAUSE_NAS_REBOOT 11
#define LIB1X_RADACCT_TERMINATE_CAUSE_PORT_INNEEDED 12
#define LIB1X_RADACCT_TERMINATE_CAUSE_PORT_PREEMPTED 13
#define LIB1X_RADACCT_TERMINATE_CAUSE_PORT_SUSPENDED 14
#define LIB1X_RADACCT_TERMINATE_CAUSE_SERVICE_UNAVAILABLE 15
#define LIB1X_RADACCT_TERMINATE_CAUSE_CALLBACK 16
#define LIB1X_RADACCT_TERMINATE_CAUSE_USER_ERROR 17
#define LIB1X_RADACCT_TERMINATE_CAUSE_HOST_REQUEST 18
#define LIB1X_RADACCT_ACTION_ACCOUNT_START 1
#define LIB1X_RADACCT_ACTION_ACCOUNT_STOP 2
#define LIB1X_RADACCT_ACTION_ACCOUNT_ON 3
#define LIB1X_RADACCT_ACTION_INTERIM_UPDATE 4
#define LIB1X_RADACCT_ACTION_TERMINATE_CAUSE 5
#define LIB1X_RAD_ACCT_STATUS_ON 1
#define LIB1X_RAD_AUTH_MAC_AUTHENTICATION 2
#define LIB1X_IPPROTO_UDP 17
#define LIB1X_80211_NAS_PORTTYPE 19 /* port type for 802.11 */
#define LIB1X_RADACCT_ACCT_ON_USER_NAME "ACCT_ON"
#define LIB1X_RAD_SERVICE_TYPE_FRAMED 2
#pragma pack(1)
#define LIB1X_CKSUM_CARRY(x) \
(x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
#define LIB1X_INC_RAD_IDENTIFIER(x) ((x==255)?x=0:x++)
//Abocom
//#define LIB1X_DEAFULT_SESSION_TIMEOUT 0x1
//#define LIB1X_DEFAULT_IDLE_TIMEOUT 0x2
//#define LIB1X_DEFAULT_INTERIM_TIMEOUT 0x3
#define LIB1X_DEAFULT_SESSION_TIMEOUT 0xffffffff
#define LIB1X_DEFAULT_IDLE_TIMEOUT 0xffffffff
#define LIB1X_DEFAULT_INTERIM_TIMEOUT 0xffffffff
struct lib1x_radiushdr
{
u_char code;
u_char identifier;
u_short length;
u_char authenticator_str[16];
};
struct lib1x_radiusattr
{
u_char type;
u_char length; // is the lengh of entire attribute including the type and length fields
};
struct lib1x_radius_vendorattr
{
u_char type;
u_char length;
u_char * string;
};
struct lib1x_udphdr
{
u_short sport; /* soure port */
u_short dport; /* destination port */
u_short len; /* length */
u_short sum; /* checksum */
};
struct lib1x_radiuspkt /* this struct is used for parsing only */
{
u_char s_ethaddr[6];
u_char d_ethaddr[6];
struct in_addr ip_src, ip_dst; /* source and dest address */
u_short dst_port, src_port;
struct lib1x_radiushdr *rhdr; // pointer to the radius start in the packet
};
struct lib1x_radius_const /* this struct is used for cosntructing packets */
{
u_char * pkt;
struct lib1x_radiushdr * rhdr;
u_short pktlen; /* length of the complete packet */
u_char * ptr_messauth;
int * nas_porttype;
};
#if 0 // move define to makefile
#ifdef _ON_RTL8181_TARGET
#undef LIB1X_LIL_ENDIAN
#endif
#endif
struct lib1x_iphdr
{
#ifdef LIB1X_LIL_ENDIAN
u_char ip_hl:4, /* header length */
ip_v:4; /* version */
#endif
#ifdef LIB1X_BIG_ENDIAN
u_char ip_v:4, /* version */
ip_hl:4; /* header length */
#endif
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off;
#ifndef IP_RF
#define IP_RF 0x8000 /* reserved fragment flag */
#endif
#ifndef IP_DF
#define IP_DF 0x4000 /* dont fragment flag */
#endif
#ifndef IP_MF
#define IP_MF 0x2000 /* more fragments flag */
#endif
#ifndef IP_OFFMASK
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
#endif
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src, ip_dst; /* source and dest address */
};
#define LIB1X_FRMSUPP_RESPID 1
#define LIB1X_FRMSUPP_RESPOTH 2
#define LIB1X_RAD_SHARED 64
#define MAX_NAS_ID_LEN 50 //sc_yang
struct radius_info /* one struct for radius related bookkeeping */
{
u_char req_authenticator[16];
u_char mess_authenticator[16];
u_char identifier; /* the identifier field in a radius packet */
/* needs to be changed for every unique packet */
u_char * global_identifier;
u_char eap_message_frmsupp[ LIB1X_MAXEAPLEN ]; /* defined in 1x_nal.h */
u_char eap_messtype_frmsupp; /* we store the received eap message from supp*/
int eap_messlen_frmsupp;
u_char eap_message_frmserver[ LIB1X_MAXEAPLEN ]; /* defined in 1x_nal.h */
u_char eap_messtype_frmserver; /* store the eap mess from server */
int eap_messlen_frmserver;
//u_char rad_shared[LIB1X_RAD_SHARED]; /* NAS and RADIUS */
u_char username[80]; /* the username attribute is what the supplicant sends in */
/* response to eap request/identity packet */
u_char username_len; /* length of the username attribute */
u_char nas_identifier[MAX_NAS_ID_LEN]; /* string identifying the Authenticator TODO .. this is so static now ! */
u_char connectinfo[50]; /* = "CONNECT 11 Mbps 802.11b" */
u_char radius_state[ LIB1X_MAXEAPLEN ]; /* State attribute .. needs to be copied back */
BOOLEAN rad_stateavailable; /* available or not */
u_short rad_statelength; /* length of the State attribute .. type 24 */
};
struct Auth_Pae_tag;
void lib1x_create_reqauth( struct Auth_Pae_tag * auth_pae );
u_short lib1x_ip_check(u_short *addr, int len);
void lib1x_do_checksum_udp(u_char *buf, int len);
void lib1x_do_checksum_ip(u_char *buf, int len);
int lib1x_in_cksum(u_short *addr, int len);
void lib1x_radconst_finalize( struct lib1x_radius_const * rconst );
void lib1x_create_messauth( struct Auth_Pae_tag * auth_pae, struct lib1x_radius_const * rconst, u_char * messauth);
void lib1x_radconst_addattr( struct lib1x_radius_const * rconst, u_char attrtype, u_char attrlen, u_char * attrdata );
void lib1x_rad_eapresp_svr( struct Auth_Pae_tag * auth_pae, struct lib1x_packet * srcpkt, int msgtype);
void lib1x_rad_eapresp_supp( struct Auth_Pae_tag * auth_pae, struct lib1x_packet * pkt);
struct lib1x_radius_const * lib1x_radconst_create( struct Auth_Pae_tag * auth_pae, u_char * pkt , u_char rcode, u_char rid, int udp_type);
int lib1x_rad_vendor_attr(Global_Params * global, u_char * rattr_ptr,int length
);
void lib1x_hmac_md5(unsigned char* text, int text_len, unsigned char* key,int key_len, caddr_t digest);
void lib1x_radconst_addEAPMessAttr( struct lib1x_radius_const * rconst, int attrlen, u_char * attrdata );
void lib1x_radconst_calradlength( struct lib1x_radius_const * rconst );
//Accounting
void lib1x_rad_session_timeout(Global_Params * global, u_char * rattr_ptr, int length);
void lib1x_rad_idle_timeout(Global_Params * global, u_char * rattr_ptr, int length);
void lib1x_rad_interim_timeout(Global_Params * global, u_char * rattr_ptr, int length);
void lib1x_rad_special_type( Auth_Pae * auth_pae, u_long ulRequestType);
void lib1x_create_reqauth_acct(Auth_Pae * auth_pae, struct lib1x_radius_const * rconst);
//MAC Authentication
int lib1x_radpassword_create( Auth_Pae * auth_pae, u_char* pucPassword, u_long ulPasswordLength);
//sc_yang
#pragma pack()
#endif

View File

@ -0,0 +1,36 @@
#ifndef LIB1x_REAUTH_SM_H
#define LIB1x_REAUTH_SM_H
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : 1x_reauth_sm.h
// Programmer : Arunesh Mishra
// Reauthentication Timer State Machine.
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//--------------------------------------------------
#include "1x_common.h"
#define LIB1X_RSM_REAUTHPERIOD 3600 //seconds
typedef struct Reauth_SM_tag
{
REAUTH_SM_STATE state;
// These are just constants as far as the ReauthSM goes.
int reAuthPeriod;
int reAuthEnabled;
} Reauth_SM;
void lib1x_reauthsm_init( Reauth_SM * reauth_sm , int reAuthTO );
void lib1x_trans_reauthsm( Global_Params * global , Reauth_SM * reauth_sm );
#endif

View File

@ -0,0 +1,222 @@
#ifndef LIB1X_SUPP_PAE_H
#define LIB1X_SUPP_PAE_H
#include "1x_common.h"
//#include "1x_nal.h"
#include "1x_types.h"
#include "1x_kmsm.h"
#include "1x_auth_pae.h"
#define LIB1X_SUPP_AUTHPERIOD 30
#define LIB1X_SUPP_HELDPERIOD 60
#define LIB1X_SUPP_STARTPERIOD 30
#define LIB1X_SUPP_MAXSTART 3
typedef enum {
skmsm_INITIALIZE,
skmsm_DISCONNECTED,
skmsm_AUTHENTICATION,
skmsm_STAKEYSTART,
skmsm_KEYUPDATE,
} SUPP_KMSM_STATE;
typedef enum {
skmsm_EVENT_AuthenticationRequest,
skmsm_EVENT_IntegrityFailure,
skmsm_EVENT_Updatekeys,
skmsm_EVENT_EAPOLKeyRecvd,
skmsm_EVENT_AuthenticationFailed,
skmsm_EVENT_DeauthenticationRequest,
skmsm_EVENT_Init,
} SUPP_KEY_MANAGE_EVENT;
struct Supp_Global_tag;
struct Supp_Kmsm_tag;
typedef struct Supp_Pae_Params_tag
{
SUPP_KMSM_STATE skmsm_state;
struct Supp_Global_tag *global;
u_char * sendBuffer;
int sendbuflen;
u_char auth_addr[ETHER_ADDRLEN];
} Supp_Pae_Params;
typedef struct Supp_Global_tag
{
// Pointer to Global Variable
Dot1x_Authenticator *auth;
struct TxRx_Params_tag * TxRx;
// Pointer to State machine
Supp_Pae_Params *supp_pae;
struct Supp_Kmsm_tag *supp_kmsm;
// Processing EAPOL Packet
OCTET_STRING EAPOLMsgRecvd; //The Overall 802.1x message
OCTET_STRING EAPOLMsgSend; //The Overall 802.1x message
OCTET_STRING EapolKeyMsgRecvd; //The start point of eapol-key payload
OCTET_STRING EapolKeyMsgSend;
//Timer related variable
u_long ConstTimerCount;
// Key handshake related
u_char DescriptorType;
u_char KeyDescriptorVer;
int AuthKeyMethod;
//RSNIE related variable
struct _DOT11_RSN_SUPPLICANT_VARIABLE RSNVariable;
} Supp_Global;
typedef struct _Dot1x_Client
{
Dot1x_Authenticator *auth;
Supp_Global *global;
Supp_Pae_Params *supp_pae;
}Dot1x_Client;
typedef struct Supp_Kmsm_tag{
LARGE_INTEGER CurrentReplayCounter;
OCTET_STRING ANonce;
OCTET_STRING SNonce;
u_char PMK[PMK_LEN];
#ifdef RTL_WPA2_CLIENT
u_char PMKID[PMKID_LEN];
#endif
u_char PTK[PTK_LEN];
u_char GTK[NumGroupKey][GTK_LEN];
#ifdef RTL_WPA2_CLIENT
u_char GTK_KEYID;
#endif
OCTET32_INTEGER Counter;
BOOLEAN bIsSetKey;
#ifdef RTL_WPA2_CLIENT
BOOLEAN bIsSetGTK;
#endif
BOOLEAN bAuthProgressing;
//Retry Mechanism
//u_long TimeCtr;
//u_long ConstTimeCtrPeriod;
u_long TimeoutCtr;
u_long PairwiseUpdateCount;
BOOLEAN bWaitForPacket;
// Key handshake related
OCTET_STRING SuppInfoElement;
OCTET_STRING AuthInfoElement;
// jimmylin 20050824
BOOLEAN bIsHndshkDone;
} Supp_Kmsm;
Supp_Global * lib1x_init_supp(
Dot1x_Authenticator * pAuth,
Dot1x_Client *pClient);
void lib1x_supp_timer_proc(
Dot1x_Client *pClient);
void lib1x_reset_supp(
Supp_Global * pGlobal);
void lib1x_do_supplicant(
Dot1x_Authenticator * pAuth,
Supp_Global * pGlobal);
void lib1x_suppsm_capture_auth(
Supp_Global * pGlobal,
lib1x_nal_intfdesc_tag * nal,
lib1x_packet_tag * spkt);
void lib1x_suppsm_capture_control(
Supp_Global * pGlobal,
lib1x_nal_intfdesc_tag * nal,
lib1x_packet_tag * spkt );
int lib1x_skmsm_EAPOLKeyRecvd(
Supp_Global * pGlobal);
void lib1x_skmsm_EAPOLKeySend(
Supp_Global * pGlobal);
void lib1x_supp_timer_proc(
Dot1x_Client *pClient);
/*
typedef struct Supp_PairwiseKeyManage_tag
{
// The machine state
SUPP_KEYSTATE state;
// The Variables.
BOOLEAN AuthenticationRequest;
BOOLEAN ReAuthenticationRequest;
BOOLEAN DeauthenticationRequest;
BOOLEAN RadiusKeyAvailable;
BOOLEAN EAPOLKeyReceived;
BOOLEAN EAPOLKeySend; //added by Emily
BOOLEAN TimeoutEvt;
int TimeoutCtr;
BOOLEAN L2Failure;
BOOLEAN MICVerified;
BOOLEAN IntegrityFailed;
BOOLEAN PInitAKeys;
OCTET_STRING ANonce;
OCTET_STRING SNonce; //added by Emily
OCTET_STRING GNonce; //added by Emily
u_char PMK[PMK_LEN];
u_char PTK[PTK_LEN];
OCTET_STRING SuppInfoElement;
LARGE_INTEGER CurrentReplayCounter;
u_char ErrorNo;
struct Global_Params_tag *global;
u_char GTK[NumGroupKey][GMK_LEN];
int GN;
int GM;
int ErroKeyType;
OCTET32_INTEGER Counter;
// Added variables that are not in IEEE 802.11i/D3.0 8.5.6.2
// but appears in state machine diagram in Figure 53(p.113)
BOOLEAN Disconnect;
BOOLEAN Init;
BOOLEAN Pair;
// The constants
}SPKeyManage_SM;
*/
#endif

View File

@ -0,0 +1,125 @@
#ifndef LIB1x_TYPES_H
#define LIB1x_TYPES_H
//--------------------------------------------------
// IEEE 802.1x Implementation
//
// File : common.h
// Programmer : Arunesh Mishra
//
// Contains all declarations of all common types.
//
//
// Copyright (c) Arunesh Mishra 2002
// All rights reserved.
// Maryland Information and Systems Security Lab
// University of Maryland, College Park.
//
//--------------------------------------------------
#ifdef _RTL_WPA_WINDOWS
typedef unsigned char u_char;
typedef unsinged short u_short;
typedef unsinged long u_long;
#else
#include <sys/types.h>
#endif
typedef enum { apsm_Initialize, apsm_Disconnected, apsm_Connecting, apsm_Authenticating, apsm_Authenticated, apsm_Aborting,
apsm_Held, apsm_Force_Auth, apsm_Force_Unauth } AUTH_PAE_STATE;
typedef enum { kxsm_No_Key_Transmit, kxsm_Key_Transmit } AUTH_KEYSM;
typedef enum { pmt_ForceUnauthorized, pmt_ForceAuthorized, pmt_Auto } PORT_MODE_TYPE;
typedef enum { pst_Unauthorized, pst_Authorized } PORT_STATUS_TYPE;
typedef enum { basm_Request, basm_Response, basm_Success, basm_Fail, basm_Timeout, basm_Idle, basm_Initialize } BAUTH_SM_STATE;
typedef enum { cdsm_Force_Both, cdsm_In_Or_Both } CTRL_SM_STATE;
typedef enum { dir_Both, dir_In } DIRECTION;
typedef enum { spsm_Logoff, spsm_Disconnected, spsm_Held, spsm_Authenticated, spsm_Connecting, spsm_Acquired, spsm_Authenticating } SUPP_PAE_STATE;
typedef enum { resm_Initialize, resm_Reauthenticate } REAUTH_SM_STATE;
typedef enum { krcsm_No_Key_Receive, krcsm_Key_Receive } KRC_SM;
// david
//typedef enum { role_Authenticator, role_Supplicant } ROLE;
typedef enum { role_Authenticator, role_Supplicant_infra, role_Supplicant_adhoc, role_wds } ROLE;
typedef enum { acctsm_Acct_No_Action, acctsm_Acct_Start, acctsm_Acct_Stop, acctsm_Acct_On, acctsm_Interim_On, acctsm_Terminate_Cause } ACCT_SM;
typedef enum { acctsm_Start, acctsm_Stop } ACCT_SM_STATE;
typedef enum { akmsm_status_NotInDriverTable, akmsm_status_Idle , akmsm_status_NotIdle } AKM_SM_STATUS;
#ifdef CONFIG_IEEE80211W
enum mfp_options {
NO_MGMT_FRAME_PROTECTION = 0,
MGMT_FRAME_PROTECTION_OPTIONAL = 1,
MGMT_FRAME_PROTECTION_REQUIRED = 2
};
#endif /* CONFIG_IEEE80211W */
typedef int BOOLEAN;
#define FALSE 0
#define TRUE 1
//Added to support WPA
#ifdef CONFIG_IEEE80211W
typedef enum { key_desc_ver1 = 1, key_desc_ver2 = 2, key_desc_ver3 = 3 } KeyDescVer;
#else
typedef enum { key_desc_ver1 = 1, key_desc_ver2 = 2 } KeyDescVer;
#endif /* CONFIG_IEEE80211W */
#ifdef RTL_WPA2
typedef enum { desc_type_WPA2 = 2, desc_type_RSN = 254 } DescTypeRSN;
#else
typedef enum { desc_type_RSN = 254 } DescTypeRSN;
#endif
typedef enum { type_Group = 0, type_Pairwise = 1 } KeyType;
//
typedef struct _OCTET_STRING
{
#ifdef RTL_WPA2
u_char * Octet;
#else
char * Octet;
#endif
int Length;
}OCTET_STRING;
typedef union _LARGE_INTEGER {
u_char charData[8];
struct{
u_long HighPart;
u_long LowPart;
}field;
} LARGE_INTEGER, *PLARGE_INTEGER;
typedef union _OCTET16_INTEGER {
u_char charData[16];
struct{
LARGE_INTEGER HighPart;
LARGE_INTEGER LowPart;
}field;
} OCTET16_INTEGER;
typedef union _OCTET32_INTEGER {
u_char charData[32];
struct{
OCTET16_INTEGER HighPart;
OCTET16_INTEGER LowPart;
}field;
}OCTET32_INTEGER;
#endif

View File

@ -0,0 +1,264 @@
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
* @(#) $Header: /cvs/AP/rtl865x/AP/auth/include/bpf.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $ (LBL)
*/
#ifndef BPF_MAJOR_VERSION
/* BSD style release date */
#define BPF_RELEASE 199606
typedef int bpf_int32;
typedef u_int bpf_u_int32;
/*
* Alignment macros. BPF_WORDALIGN rounds up to the next
* even multiple of BPF_ALIGNMENT.
*/
#define BPF_ALIGNMENT sizeof(bpf_int32)
#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
#define BPF_MAXINSNS 512
#define BPF_MAXBUFSIZE 0x8000
#define BPF_MINBUFSIZE 32
/*
* Structure for BIOCSETF.
*/
struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;
};
/*
* Struct returned by BIOCGSTATS.
*/
struct bpf_stat {
u_int bs_recv; /* number of packets received */
u_int bs_drop; /* number of packets dropped */
};
/*
* Struct return by BIOCVERSION. This represents the version number of
* the filter language described by the instruction encodings below.
* bpf understands a program iff kernel_major == filter_major &&
* kernel_minor >= filter_minor, that is, if the value returned by the
* running kernel has the same major number and a minor number equal
* equal to or less than the filter being downloaded. Otherwise, the
* results are undefined, meaning an error may be returned or packets
* may be accepted haphazardly.
* It has nothing to do with the source code version.
*/
struct bpf_version {
u_short bv_major;
u_short bv_minor;
};
/* Current version number of filter architecture. */
#define BPF_MAJOR_VERSION 1
#define BPF_MINOR_VERSION 1
/*
* BPF ioctls
*
* The first set is for compatibility with Sun's pcc style
* header files. If your using gcc, we assume that you
* have run fixincludes so the latter set should work.
*/
#if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
#define BIOCGBLEN _IOR(B,102, u_int)
#define BIOCSBLEN _IOWR(B,102, u_int)
#define BIOCSETF _IOW(B,103, struct bpf_program)
#define BIOCFLUSH _IO(B,104)
#define BIOCPROMISC _IO(B,105)
#define BIOCGDLT _IOR(B,106, u_int)
#define BIOCGETIF _IOR(B,107, struct ifreq)
#define BIOCSETIF _IOW(B,108, struct ifreq)
#define BIOCSRTIMEOUT _IOW(B,109, struct timeval)
#define BIOCGRTIMEOUT _IOR(B,110, struct timeval)
#define BIOCGSTATS _IOR(B,111, struct bpf_stat)
#define BIOCIMMEDIATE _IOW(B,112, u_int)
#define BIOCVERSION _IOR(B,113, struct bpf_version)
#define BIOCSTCPF _IOW(B,114, struct bpf_program)
#define BIOCSUDPF _IOW(B,115, struct bpf_program)
#else
#define BIOCGBLEN _IOR('B',102, u_int)
#define BIOCSBLEN _IOWR('B',102, u_int)
#define BIOCSETF _IOW('B',103, struct bpf_program)
#define BIOCFLUSH _IO('B',104)
#define BIOCPROMISC _IO('B',105)
#define BIOCGDLT _IOR('B',106, u_int)
#define BIOCGETIF _IOR('B',107, struct ifreq)
#define BIOCSETIF _IOW('B',108, struct ifreq)
#define BIOCSRTIMEOUT _IOW('B',109, struct timeval)
#define BIOCGRTIMEOUT _IOR('B',110, struct timeval)
#define BIOCGSTATS _IOR('B',111, struct bpf_stat)
#define BIOCIMMEDIATE _IOW('B',112, u_int)
#define BIOCVERSION _IOR('B',113, struct bpf_version)
#define BIOCSTCPF _IOW('B',114, struct bpf_program)
#define BIOCSUDPF _IOW('B',115, struct bpf_program)
#endif
/*
* Structure prepended to each packet.
*/
struct bpf_hdr {
struct timeval bh_tstamp; /* time stamp */
bpf_u_int32 bh_caplen; /* length of captured portion */
bpf_u_int32 bh_datalen; /* original length of packet */
u_short bh_hdrlen; /* length of bpf header (this struct
plus alignment padding) */
};
/*
* Because the structure above is not a multiple of 4 bytes, some compilers
* will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
* Only the kernel needs to know about it; applications use bh_hdrlen.
*/
#ifdef KERNEL
#define SIZEOF_BPF_HDR 18
#endif
/*
* Data-link level type codes.
*/
#define DLT_NULL 0 /* no link-layer encapsulation */
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
#define DLT_AX25 3 /* Amateur Radio AX.25 */
#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
#define DLT_CHAOS 5 /* Chaos */
#define DLT_IEEE802 6 /* IEEE 802 Networks */
#define DLT_ARCNET 7 /* ARCNET */
#define DLT_SLIP 8 /* Serial Line IP */
#define DLT_PPP 9 /* Point-to-point Protocol */
#define DLT_FDDI 10 /* FDDI */
#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
#define DLT_RAW 12 /* raw IP */
#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */
#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */
/*
* The instruction encondings.
*/
/* instruction classes */
#define BPF_CLASS(code) ((code) & 0x07)
#define BPF_LD 0x00
#define BPF_LDX 0x01
#define BPF_ST 0x02
#define BPF_STX 0x03
#define BPF_ALU 0x04
#define BPF_JMP 0x05
#define BPF_RET 0x06
#define BPF_MISC 0x07
/* ld/ldx fields */
#define BPF_SIZE(code) ((code) & 0x18)
#define BPF_W 0x00
#define BPF_H 0x08
#define BPF_B 0x10
#define BPF_MODE(code) ((code) & 0xe0)
#define BPF_IMM 0x00
#define BPF_ABS 0x20
#define BPF_IND 0x40
#define BPF_MEM 0x60
#define BPF_LEN 0x80
#define BPF_MSH 0xa0
/* alu/jmp fields */
#define BPF_OP(code) ((code) & 0xf0)
#define BPF_ADD 0x00
#define BPF_SUB 0x10
#define BPF_MUL 0x20
#define BPF_DIV 0x30
#define BPF_OR 0x40
#define BPF_AND 0x50
#define BPF_LSH 0x60
#define BPF_RSH 0x70
#define BPF_NEG 0x80
#define BPF_JA 0x00
#define BPF_JEQ 0x10
#define BPF_JGT 0x20
#define BPF_JGE 0x30
#define BPF_JSET 0x40
#define BPF_SRC(code) ((code) & 0x08)
#define BPF_K 0x00
#define BPF_X 0x08
/* ret - BPF_K and BPF_X also apply */
#define BPF_RVAL(code) ((code) & 0x18)
#define BPF_A 0x10
/* misc */
#define BPF_MISCOP(code) ((code) & 0xf8)
#define BPF_TAX 0x00
#define BPF_TXA 0x80
/*
* The instruction data structure.
*/
struct bpf_insn {
u_short code;
u_char jt;
u_char jf;
bpf_int32 k;
};
/*
* Macros for insn array initializers.
*/
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
#ifdef KERNEL
extern u_int bpf_filter();
extern void bpfattach();
extern void bpf_tap();
extern void bpf_mtap();
#else
#if __STDC__
extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
#endif
#endif
/*
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
#define BPF_MEMWORDS 16
#endif

View File

@ -0,0 +1,47 @@
/* include/config.h. Generated automatically by configure. */
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
/* Define to empty if the keyword does not work. */
/* #undef const */
/* #undef LIBNET_BSDISH_OS */
/* #undef LIBNET_BSD_BYTE_SWAP */
/* #undef DLPI_DEV_PREFIX */
/* #undef HAVE_DEV_DLPI */
/* #undef HAVE_SOCKADDR_SA_LEN */
/* #undef HAVE_SOLARIS */
/* #undef HAVE_DLPI */
/* #undef HAVE_PF_PACKET */
/* #undef HAVE_STRUCT_IP_CSUM */
#define HAVE_LIB_PCAP 1
/* #undef LBL_ALIGN */
/* #undef STUPID_SOLARIS_CHECKSUM_BUG */
#define _BSD_SOURCE 1
#define __BSD_SOURCE 1
#define __FAVOR_BSD 1
#if 0 // move define to Makefile
#undef LIBNET_LIL_ENDIAN
#define LIBNET_BIG_ENDIAN 1
/*#define LIBNET_LIL_ENDIAN 1*/
#endif
/* Define if you have the strerror function. */
#define HAVE_STRERROR 1
/* Define if you have the <net/ethernet.h> header file. */
#define HAVE_NET_ETHERNET_H 1
/* Define if you have the <sys/bufmod.h> header file. */
/* #undef HAVE_SYS_BUFMOD_H */
/* Define if you have the <sys/dlpi_ext.h> header file. */
/* #undef HAVE_SYS_DLPI_EXT_H */
/* Define if you have the <sys/sockio.h> header file. */
/* #undef HAVE_SYS_SOCKIO_H */
/* Define if you have the nsl library (-lnsl). */
/* #undef HAVE_LIBNSL */
/* Define if you have the socket library (-lsocket). */
/* #undef HAVE_LIBSOCKET */

View File

@ -0,0 +1,97 @@
/*
* $Id: libnet.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet.h - Network routine library header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_H
#define __LIBNET_H
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#if defined(HAVE_SYS_SOCKIO_H) && !defined(SIOCGIFADDR)
#include <sys/sockio.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <net/if.h>
#ifndef __linux__
#include <netinet/ip_var.h>
#else /* __linux__ */
//#ifdef HAVE_NET_ETHERNET_H
//#include <net/ethernet.h>
//#endif /* HAVE_NET_ETHERNET_H */
#if defined(__GLIBC__) && (__GLIBC__)
#include <netinet/if_ether.h>
#else
#include <linux/if_ether.h>
#endif
#endif /* __linux__ */
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>
#if defined(__linux__) && (!defined(__GLIBC__) || !(__GLIBC__))
/*
* We get multiple definitions of IGMP_AGE_THRESHOLD if we include netinet.
*/
//#include <linux/igmp.h> acli
#else
#include <netinet/igmp.h>
#endif
#include <arpa/inet.h>
#include <sys/time.h>
#include <netdb.h>
#include <errno.h>
#include <assert.h>
#include "./libnet/libnet-headers.h"
#include "./libnet/libnet-structures.h"
#include "./libnet/libnet-macros.h"
#include "./libnet/libnet-asn1.h"
#include "./libnet/libnet-functions.h"
#include "./libnet/libnet-ospf.h"
#define LIBNET_VERSION "1.0.2a"
#if (!LIBNET_LIL_ENDIAN && !LIBNET_BIG_ENDIAN)
#error "byte order has not been specified, you'll need to #define either LIBNET_LIL_ENDIAN or LIBNET_BIG_ENDIAN. See the documentation regarding the libnet-config script."
#endif
#endif /* __LIBNET_H */
/* EOF */

View File

@ -0,0 +1,251 @@
/*
* $Id: libnet-asn1.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-asn1.h - Network routine library ASN.1 header file
*
* Definitions for Abstract Syntax Notation One, ASN.1
* As defined in ISO/IS 8824 and ISO/IS 8825
*
* Copyright 1988, 1989 by Carnegie Mellon University
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of CMU not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __LIBNET_ASN1_H
#define __LIBNET_ASN1_H
#ifndef EIGHTBIT_SUBIDS
typedef u_long oid;
#define MAX_SUBID 0xFFFFFFFF
#else
typedef u_char oid;
#define MAX_SUBID 0xFF
#endif
#define MAX_OID_LEN 64 /* max subid's in an oid */
#define ASN_BOOLEAN (0x01)
#define ASN_INTEGER (0x02)
#define ASN_BIT_STR (0x03)
#define ASN_OCTET_STR (0x04)
#define ASN_NULL (0x05)
#define ASN_OBJECT_ID (0x06)
#define ASN_SEQUENCE (0x10)
#define ASN_SET (0x11)
#define ASN_UNIVERSAL (0x00)
#define ASN_APPLICATION (0x40)
#define ASN_CONTEXT (0x80)
#define ASN_PRIVATE (0xC0)
#define ASN_PRIMITIVE (0x00)
#define ASN_CONSTRUCTOR (0x20)
#define ASN_LONG_LEN (0x80)
#define ASN_EXTENSION_ID (0x1F)
#define ASN_BIT8 (0x80)
#define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR)
#define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) = ASN_EXTENSION_ID)
/*
* All of the build_asn1_* (build_asn1_length being an exception) functions
* take the same first 3 arguments:
*
* u_char *data: This is a pointer to the start of the data object to be
* manipulated.
* int *datalen: This is a pointer to the number of valid bytes following
* "data". This should be not be exceeded in any function.
* Upon exiting a function, this value will reflect the
* changed "data" and then refer to the new number of valid
* bytes until the end of "data".
* u_char type: The ASN.1 object type.
*/
/*
* Builds an ASN object containing an integer.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_int(
u_char *, /* Pointer to the output buffer */
int *, /* Number of valid bytes left in the buffer */
u_char, /* ASN object type */
long *, /* Pointer to a long integer */
int /* Size of a long integer */
);
/*
* Builds an ASN object containing an unsigned integer.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_uint(
u_char *, /* Pointer to the output buffer */
int *, /* Number of valid bytes left in the buffer */
u_char, /* ASN object type */
u_long *, /* Pointer to an unsigned long integer */
int /* Size of a long integer */
);
/*
* Builds an ASN object containing an octect string.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_string(
u_char *, /* Pointer to the output buffer */
int *, /* Number of valid bytes left in the buffer */
u_char, /* ASN object type */
u_char *, /* Pointer to a string to be built into an object */
int /* Size of the string */
);
/*
* Builds an ASN header for an object with the ID and length specified. This
* only works on data types < 30, i.e. no extension octets. The maximum
* length is 0xFFFF;
*
* Returns a pointer to the first byte of the contents of this object or
* NULL upon error
*/
u_char *
libnet_build_asn1_header(
u_char *, /* Pointer to the start of the object */
int *, /* Number of valid bytes left in buffer */
u_char, /* ASN object type */
int /* ASN object length */
);
u_char *
libnet_build_asn1_length(
u_char *, /* Pointer to start of object */
int *, /* Number of valid bytes in buffer */
int /* Length of object */
);
/*
* Builds an ASN header for a sequence with the ID and length specified.
*
* This only works on data types < 30, i.e. no extension octets.
* The maximum length is 0xFFFF;
*
* Returns a pointer to the first byte of the contents of this object.
* Returns NULL on any error.
*/
u_char *
libnet_build_asn1_sequence(
u_char *,
int *,
u_char,
int
);
/*
* Builds an ASN object identifier object containing the input string.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_objid(
u_char *,
int *,
u_char,
oid *,
int
);
/*
* Builds an ASN null object.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_null(
u_char *,
int *,
u_char
);
/*
* Builds an ASN bitstring.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_bitstring(
u_char *,
int *,
u_char,
u_char *, /* Pointer to the input buffer */
int /* Length of the input buffer */
);
#endif /* __LIBNET_ASN1_H */
/* EOF */

View File

@ -0,0 +1,658 @@
/*
* $Id: libnet-functions.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-functions.h - Network routine library function prototype header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_FUNCTIONS_H
#define __LIBNET_FUNCTIONS_H
int /* 1 if good, -1 if bad */
libnet_plist_chain_new(
struct libnet_plist_chain **, /* pointer to the head of the list */
char * /* token list pointer */
);
int /* 1 if more nodes, 0 if not */
libnet_plist_chain_next_pair(
struct libnet_plist_chain *, /* pointer to the head of the list */
u_short *, /* holds bport */
u_short * /* holds eport */
);
int
libnet_plist_chain_dump(
struct libnet_plist_chain * /* pointer to the head of the list */
);
u_char *
libnet_plist_chain_dump_string(
struct libnet_plist_chain * /* pointer to the head of the list */
);
int
libnet_plist_chain_free(
struct libnet_plist_chain * /* pointer to the head of the list */
);
/*
* Standard error handling code.
*/
void
libnet_error(
int, /* severity */
char *, /* error message */
... /* varargs */
);
/*
* Seeds the pseudorandom number generator with gettimeofday.
*/
int
libnet_seed_prand();
/*
* Returns a psuedorandom positive integer.
*/
u_long
libnet_get_prand(
int /* One of the PR* constants */
);
/*
* Calculates IPv4 family checksum on packet headers.
*/
int /* 1 on success, -1 on failure */
libnet_do_checksum(
u_char *, /* Pointer to the packet buffer */
int, /* Protocol */
int /* Packet size */
);
/*
* Network byte order into IP address
* Previous versions had a memory leak (returned a strdup'd pointer -- strdup
* has an implicit malloc which wasn't getting freed). This static var hack
* thingy was used to preserve existing code without having to change much.
* You can simply use the return value of the function directly allowing you
* to write tighter, more obvious code (rather then having to do allocate an
* additional buffer for the output).
* Thanks to Red for the idea.
*/
u_char * /* Pointer to hostname or dotted decimal IP address */
libnet_host_lookup(
u_long, /* Network byte ordered (big endian) IP address */
u_short /* Use domain names or no */
);
/*
* Network byte order into IP address
* Threadsafe version.
*/
void
libnet_host_lookup_r(
u_long, /* Network byte ordered (big endian) IP address */
u_short, /* Use domain names or no */
u_char * /* Pointer to hostname or dotted decimal IP address */
);
/*
* IP address into network byte order
*/
u_long /* Network byte ordered IP address or -1 on error */
libnet_name_resolve(
u_char *, /* Pointer the hostname or dotted decimal IP address */
u_short /* Use domain names or no */
);
/*
* IP checksum wrapper.
*/
u_short /* Standard IP checksum of header and data */
libnet_ip_check(
u_short *, /* Pointer to the buffer to be summed */
int /* Packet length */
);
/*
* IP checksum.
*/
int /* Standard IP checksum */
libnet_in_cksum(
u_short *, /* Pointer to the buffer to be summed */
int /* Packet length */
);
/*
* Opens a socket for writing raw IP datagrams to. Set IP_HDRINCL to let the
* kernel know we've got it all under control.
*/
int /* Opened file desciptor, or -1 on error */
libnet_open_raw_sock(
int /* Protocol of raw socket (from /etc/protocols) */
);
int /* 1 upon success, or -1 on error */
libnet_close_raw_sock(
int /* File descriptor */
);
int
libnet_select_device(
struct sockaddr_in *,
char **,
char *
);
/*
* Ethernet packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_ethernet(
u_char *, /* Pointer to a 6 byte ethernet address */
u_char *, /* Pointer to a 6 byte ethernet address */
u_short, /* Packet IP type */
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Packet header buffer */
);
/*
* ARP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_arp(
u_short, /* hardware address type */
u_short, /* protocol address type */
u_char, /* hardware address length */
u_char, /* protocol address length */
u_short, /* ARP operation type */
u_char *, /* sender hardware address */
u_char *, /* sender protocol address */
u_char *, /* target hardware address */
u_char *, /* target protocol address */
const u_char *, /* payload or NULL if none */
int, /* payload length */
u_char * /* packet buffer memory */
);
/*
* TCP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_tcp(
u_short, /* Source port */
u_short, /* Destination port */
u_long, /* Sequence Number */
u_long, /* Acknowledgement Number */
u_char, /* Control bits */
u_short, /* Advertised Window Size */
u_short, /* Urgent Pointer */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* UDP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_udp(
u_short, /* Source port */
u_short, /* Destination port */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_ECHO packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_echo(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* id */
u_short, /* sequence number */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_MASK packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_mask(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* id */
u_short, /* sequence number */
u_long, /* address mask */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_UNREACH packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_unreach(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* Original Length of packet data */
u_char, /* Original IP tos */
u_short, /* Original IP ID */
u_short, /* Original Fragmentation flags and offset */
u_char, /* Original TTL */
u_char, /* Original Protocol */
u_long, /* Original Source IP Address */
u_long, /* Original Destination IP Address */
const u_char *, /* Pointer to original packet data (or NULL) */
int, /* Packet payload size (or 0) */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_REDIRECT packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_redirect(
u_char, /* icmp type */
u_char, /* icmp code */
u_long, /* Gateway host that should be used */
u_short, /* Original Length of packet data */
u_char, /* Original IP tos */
u_short, /* Original IP ID */
u_short, /* Original Fragmentation flags and offset */
u_char, /* Original TTL */
u_char, /* Original Protocol */
u_long, /* Original Source IP Address */
u_long, /* Original Destination IP Address */
const u_char *, /* Pointer to original packet data (or NULL) */
int, /* Packet payload size (or 0) */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_TIMXCEED packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_timeexceed(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* Original Length of packet data */
u_char, /* Original IP tos */
u_short, /* Original IP ID */
u_short, /* Original Fragmentation flags and offset */
u_char, /* Original TTL */
u_char, /* Original Protocol */
u_long, /* Original Source IP Address */
u_long, /* Original Destination IP Address */
const u_char *, /* Pointer to original packet data (or NULL) */
int, /* Packet payload size (or 0) */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_TIMESTAMP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_timestamp(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* id */
u_short, /* sequence number */
n_time, /* original timestamp */
n_time, /* receive timestamp */
n_time, /* transmit timestamp */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* IGMP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_igmp(
u_char, /* igmp type */
u_char, /* igmp code */
u_long, /* ip addr */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* IPv4 packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_ip(
u_short, /* Length of packet data */
u_char, /* IP tos */
u_short, /* IP ID */
u_short, /* Fragmentation flags and offset */
u_char, /* TTL */
u_char, /* Protocol */
u_long, /* Source IP Address */
u_long, /* Destination IP Address */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_ipv4(
u_short, /* Length of packet data */
u_char, /* IP tos */
u_short, /* IP ID */
u_short, /* Fragmentation flags and offset */
u_char, /* TTL */
u_char, /* Protocol */
u_long, /* Source IP Address */
u_long, /* Destination IP Address */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* DNS pacekt assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_dns(
u_short, /* Packet ID */
u_short, /* Flags */
u_short, /* Number of questions */
u_short, /* Number of answer resource records */
u_short, /* Number of authority resource records */
u_short, /* Number of additional resource records */
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Header memory */
);
/*
* RIP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_rip(
u_char, /* Command */
u_char, /* Version */
u_short, /* Zero (v1) or Routing Domain (v2) */
u_short, /* Address family */
u_short, /* Zero (v1) or Route Tag (v2) */
u_long, /* IP address */
u_long, /* Zero (v1) or Subnet Mask (v2) */
u_long, /* Zero (v1) or Next hop IP address (v2) */
u_long, /* Metric */
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Header memory */
);
/*
* VRRP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_vrrp(
u_char,
u_char,
u_char,
u_char,
u_char,
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Header memory */
);
int
libnet_init_vrrp_packet(size_t,
u_char **,
u_char
);
/*
* Insert IP options to a prebuilt IP packet.
*/
int /* 1 on success, -1 on failure */
libnet_insert_ipo(
struct ipoption *, /* Pointer to the ip options structure */
u_char, /* IP option list size */
u_char * /* Pointer to packet buf */
);
/*
* Insert TCP options to a prebuilt IP packet.
*/
int /* 1 on success, -1 on failure */
libnet_insert_tcpo(
struct tcpoption *, /* Pointer to the tcp options structure */
u_char, /* TCP option list size */
u_char * /* Pointer to packet buf */
);
/*
* Writes a prebuild IP packet to the network with a supplied raw socket.
* To write a link layer packet, use the write_link_layer function.
*/
int /* number of bytes written if successful, -1 on error */
libnet_write_ip(
int sock, /* Previously opened raw socket */
u_char *, /* Pointer a complete IP datagram */
int /* Packet size */
);
/*
* Writes a prebuild IP/ethernet packet to the network with a supplied
* link_layer interface. To write just an IP packet, use the write_link_layer
* function.
*/
int /* number of bytes written if successful, -1 on error */
libnet_write_link_layer(
struct libnet_link_int *, /* Pointer to a link interface structure */
const char *, /* Pointer to the device */
u_char *, /* Pointer the u_char buf (the packet)to be written */
int /* Packet length */
);
/*
* Opens a link layer interface. Analogous to open_raw_sock.
*/
struct libnet_link_int * /* Pointer to a link layer interface struct */
libnet_open_link_interface(
char *, /* Device name */
char * /* Error buffer */
);
int /* 1 on success, -1 on failure */
libnet_close_link_interface(
struct libnet_link_int * /* Pointer to a link layer interface struct */
);
char * /* String error message */
ll_strerror(
int /* Errno */
);
/*
* Returns the IP address of the interface.
*/
u_long /* 0 upon error, address upon success */
libnet_get_ipaddr(
struct libnet_link_int *, /* Pointer to a link interface structure */
const char *, /* Device */
char * /* Error buf */
);
/*
* Returns the MAC address of the interface.
*/
struct ether_addr * /* 0 upon error, address upon success */
libnet_get_hwaddr(
struct libnet_link_int *, /* Pointer to a link interface structure */
const char *, /* Device */
char * /* Error buf */
);
/*
* Simple interface for initializing a packet.
* Basically a malloc wrapper.
*/
int /* -1 on error, 1 on ok */
libnet_init_packet(
int, /* 0 and we make a good guess, otherwise you choose. */
u_char ** /* Pointer to the pointer to the packet */
);
/*
* Simple interface for destoying a packet.
* Don't call this without a corresponding call to init_packet() first.
*/
int /* -1 if arena is NULL, 1 if ok */
libnet_destroy_packet(
u_char ** /* Pointer to the packet addr. */
);
/*
* Memory pool initialization routine.
*/
int
libnet_init_packet_arena(
struct libnet_arena **, /* Pointer to an arena pointer */
int, /* 0 and we make a good guess, otherwise you choose. */
u_short
);
/*
* Returns the next chunk of memory from the pool.
*/
u_char *
libnet_next_packet_from_arena(
struct libnet_arena **, /* Pointer to an arena pointer */
int /* 0 and we make a good guess, otherwise you choose. */
);
/*
* Memory pool destructor routine.
*/
int /* -1 if arena is NULL, 1 if ok */
libnet_destroy_packet_arena(
struct libnet_arena ** /* Pointer to an arena pointer */
);
/*
* More or less taken from tcpdump code.
*/
void
libnet_hex_dump(
u_char *, /* Packet to be dumped */
int, /* Packet size (in bytes */
int, /* To swap or not to swap */
FILE * /* Stream pointer to dump to */
);
#endif /* __LIBNET_FUNCTIONS_H */
/* EOF */

View File

@ -0,0 +1,525 @@
/*
* $Id: libnet-headers.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-headers.h - Network routine library headers header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_HEADERS_H
#define __LIBNET_HEADERS_H
/*
* Standard (IPv4) header sizes in bytes.
*/
#define LIBNET_ARP_H 0x1c /* ARP header: 28 bytes */
#define LIBNET_DNS_H 0xc /* DNS header base: 12 bytes */
#define LIBNET_ETH_H 0xe /* Etherner header: 14 bytes */
#define LIBNET_ICMP_H 0x4 /* ICMP header base: 4 bytes */
#define LIBNET_ICMP_ECHO_H 0x8 /* ICMP_ECHO header: 8 bytes */
#define LIBNET_ICMP_MASK_H 0xc /* ICMP_MASK header: 12 bytes */
#define LIBNET_ICMP_UNREACH_H 0x8 /* ICMP_UNREACH header: 8 bytes */
#define LIBNET_ICMP_TIMXCEED_H 0x8 /* ICMP_TIMXCEED header: 8 bytes */
#define LIBNET_ICMP_REDIRECT_H 0x8 /* ICMP_REDIRECT header: 8 bytes */
#define LIBNET_ICMP_TS_H 0x14 /* ICMP_TIMESTAMP headr:20 bytes */
#define LIBNET_IGMP_H 0x8 /* IGMP header: 8 bytes */
#define LIBNET_IP_H 0x14 /* IP header: 20 bytes */
/* See libnet-ospf.h for OSPF related header sizes */
#define LIBNET_RIP_H 0x18 /* RIP header base: 24 bytes */
#define LIBNET_TCP_H 0x14 /* TCP header: 20 bytes */
#define LIBNET_UDP_H 0x8 /* UDP header: 8 bytes */
#define LIBNET_VRRP_H 0x8 /* VRRP header: 8 bytes */
/*
* Concession to legacy naming scheme.
*/
#define ARP_H LIBNET_ARP_H
#define DNS_H LIBNET_DNS_H
#define ETH_H LIBNET_ETH_H
#define ICMP_H LIBNET_ICMP_H
#define ICMP_ECHO_H LIBNET_ICMP_ECHO_H
#define ICMP_MASK_H LIBNET_ICMP_MASK_H
#define ICMP_UNREACH_H LIBNET_ICMP_UNREACH_H
#define ICMP_TIMXCEED_H LIBNET_ICMP_TIMXCEED_H
#define ICMP_REDIRECT_H LIBNET_ICMP_REDIRECT_H
#define ICMP_TS_H LIBNET_ICMP_TS_H
#define IGMP_H LIBNET_IGMP_H
#define IP_H LIBNET_IP_H
#define RIP_H LIBNET_RIP_H
#define TCP_H LIBNET_TCP_H
#define UDP_H LIBNET_UDP_H
/*
* IPv4 packet header prototype.
*/
struct libnet_ip_hdr
{
#if (LIBNET_LIL_ENDIAN)
u_char ip_hl:4, /* header length */
ip_v:4; /* version */
#endif
#if (LIBNET_BIG_ENDIAN)
u_char ip_v:4, /* version */
ip_hl:4; /* header length */
#endif
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off;
#ifndef IP_RF
#define IP_RF 0x8000 /* reserved fragment flag */
#endif
#ifndef IP_DF
#define IP_DF 0x4000 /* dont fragment flag */
#endif
#ifndef IP_MF
#define IP_MF 0x2000 /* more fragments flag */
#endif
#ifndef IP_OFFMASK
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
#endif
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src, ip_dst; /* source and dest address */
};
/*
* TCP packet header prototype.
*/
struct libnet_tcp_hdr
{
u_short th_sport; /* source port */
u_short th_dport; /* destination port */
u_long th_seq; /* sequence number */
u_long th_ack; /* acknowledgement number */
#if (LIBNET_LIL_ENDIAN)
u_char th_x2:4, /* (unused) */
th_off:4; /* data offset */
#endif
#if (LIBNET_BIG_ENDIAN)
u_char th_off:4, /* data offset */
th_x2:4; /* (unused) */
#endif
u_char th_flags; /* control flags */
#ifndef TH_FIN
#define TH_FIN 0x01
#endif
#ifndef TH_SYN
#define TH_SYN 0x02
#endif
#ifndef TH_RST
#define TH_RST 0x04
#endif
#ifndef TH_PUSH
#define TH_PUSH 0x08
#endif
#ifndef TH_ACK
#define TH_ACK 0x10
#endif
#ifndef TH_URG
#define TH_URG 0x20
#endif
u_short th_win; /* window */
u_short th_sum; /* checksum */
u_short th_urp; /* urgent pointer */
};
/*
* UDP packet header prototype.
*/
struct libnet_udp_hdr
{
u_short uh_sport; /* soure port */
u_short uh_dport; /* destination port */
u_short uh_ulen; /* length */
u_short uh_sum; /* checksum */
};
/*
* ICMP packet header prototype.
*/
struct libnet_icmp_hdr
{
u_char icmp_type;
/*
* ICMP types.
*/
#ifndef ICMP_ECHOREPLY
#define ICMP_ECHOREPLY 0
#endif
#ifndef ICMP_UNREACH
#define ICMP_UNREACH 3
#endif
#ifndef ICMP_SOURCEQUENCH
#define ICMP_SOURCEQUENCH 4
#endif
#ifndef ICMP_REDIRECT
#define ICMP_REDIRECT 5
#endif
#ifndef ICMP_ECHO
#define ICMP_ECHO 8
#endif
#ifndef ICMP_ROUTERADVERT
#define ICMP_ROUTERADVERT 9
#endif
#ifndef ICMP_ROUTERSOLICIT
#define ICMP_ROUTERSOLICIT 10
#endif
#ifndef ICMP_TIMXCEED
#define ICMP_TIMXCEED 11
#endif
#ifndef ICMP_PARAMPROB
#define ICMP_PARAMPROB 12
#endif
#ifndef ICMP_TSTAMP
#define ICMP_TSTAMP 13
#endif
#ifndef ICMP_TSTAMPREPLY
#define ICMP_TSTAMPREPLY 14
#endif
#ifndef ICMP_IREQ
#define ICMP_IREQ 15
#endif
#ifndef ICMP_IREQREPLY
#define ICMP_IREQREPLY 16
#endif
#ifndef ICMP_MASKREQ
#define ICMP_MASKREQ 17
#endif
#ifndef ICMP_MASKREPLY
#define ICMP_MASKREPLY 18
#endif
u_char icmp_code;
/*
* ICMP codes.
*/
#ifndef ICMP_UNREACH_NET
#define ICMP_UNREACH_NET 0
#endif
#ifndef ICMP_UNREACH_HOST
#define ICMP_UNREACH_HOST 1
#endif
#ifndef ICMP_UNREACH_PROTOCOL
#define ICMP_UNREACH_PROTOCOL 2
#endif
#ifndef ICMP_UNREACH_PORT
#define ICMP_UNREACH_PORT 3
#endif
#ifndef ICMP_UNREACH_NEEDFRAG
#define ICMP_UNREACH_NEEDFRAG 4
#endif
#ifndef ICMP_UNREACH_SRCFAIL
#define ICMP_UNREACH_SRCFAIL 5
#endif
#ifndef ICMP_UNREACH_NET_UNKNOWN
#define ICMP_UNREACH_NET_UNKNOWN 6
#endif
#ifndef ICMP_UNREACH_HOST_UNKNOWN
#define ICMP_UNREACH_HOST_UNKNOWN 7
#endif
#ifndef ICMP_UNREACH_ISOLATED
#define ICMP_UNREACH_ISOLATED 8
#endif
#ifndef ICMP_UNREACH_NET_PROHIB
#define ICMP_UNREACH_NET_PROHIB 9
#endif
#ifndef ICMP_UNREACH_HOST_PROHIB
#define ICMP_UNREACH_HOST_PROHIB 10
#endif
#ifndef ICMP_UNREACH_TOSNET
#define ICMP_UNREACH_TOSNET 11
#endif
#ifndef ICMP_UNREACH_TOSHOST
#define ICMP_UNREACH_TOSHOST 12
#endif
#ifndef ICMP_UNREACH_FILTER_PROHIB
#define ICMP_UNREACH_FILTER_PROHIB 13
#endif
#ifndef ICMP_UNREACH_HOST_PRECEDENCE
#define ICMP_UNREACH_HOST_PRECEDENCE 14
#endif
#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
#endif
#ifndef ICMP_REDIRECT_NET
#define ICMP_REDIRECT_NET 0
#endif
#ifndef ICMP_REDIRECT_HOST
#define ICMP_REDIRECT_HOST 1
#endif
#ifndef ICMP_REDIRECT_TOSNET
#define ICMP_REDIRECT_TOSNET 2
#endif
#ifndef ICMP_REDIRECT_TOSHOST
#define ICMP_REDIRECT_TOSHOST 3
#endif
#ifndef ICMP_TIMXCEED_INTRANS
#define ICMP_TIMXCEED_INTRANS 0
#endif
#ifndef ICMP_TIMXCEED_REASS
#define ICMP_TIMXCEED_REASS 1
#endif
#ifndef ICMP_PARAMPROB_OPTABSENT
#define ICMP_PARAMPROB_OPTABSENT 1
#endif
u_short icmp_sum;
union
{
struct
{
u_short id;
u_short seq;
}echo;
#undef icmp_id
#undef icmp_seq
#define icmp_id hun.echo.id
#define icmp_seq hun.echo.seq
u_long gateway;
struct
{
u_short pad;
u_short mtu;
}frag;
}hun;
union
{
struct
{
n_time its_otime;
n_time its_rtime;
n_time its_ttime;
}ts;
struct
{
struct ip idi_ip;
/* options and then 64 bits of data */
}ip;
u_long mask;
char data[1];
#undef icmp_mask
#define icmp_mask dun.mask
#undef icmp_data
#define icmp_data dun.data
#undef icmp_otime
#define icmp_otime dun.ts.its_otime
#undef icmp_rtime
#define icmp_rtime dun.ts.its_rtime
#undef icmp_ttime
#define icmp_ttime dun.ts.its_ttime
}dun;
};
/*
* IGMP header.
*/
struct libnet_igmp_hdr
{
u_char igmp_type;
#ifndef IGMP_MEMBERSHIP_QUERY
#define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */
#endif
#ifndef IGMP_V1_MEMBERSHIP_REPORT
#define IGMP_V1_MEMBERSHIP_REPORT 0x12 /* Ver. 1 membership report */
#endif
#ifndef IGMP_V2_MEMBERSHIP_REPORT
#define IGMP_V2_MEMBERSHIP_REPORT 0x16 /* Ver. 2 membership report */
#endif
#ifndef IGMP_LEAVE_GROUP
#define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */
#endif
u_char igmp_code;
u_short igmp_sum;
struct in_addr igmp_group;
};
/*
* Ethernet packet header prototype. Too many O/S's define this differently.
* Easy enough to solve that and define it here.
*/
struct libnet_ethernet_hdr
{
#ifndef ETHER_ADDR_LEN
#define ETHER_ADDR_LEN 6
#endif
u_char ether_dhost[ETHER_ADDR_LEN]; /* destination ethernet address */
u_char ether_shost[ETHER_ADDR_LEN]; /* source ethernet address */
u_short ether_type; /* packet type ID */
};
#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
#define ETHERTYPE_IP 0x0800 /* IP protocol */
#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */
#define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */
#ifndef __ANDROID__
#if !defined(__GLIBC__) || (!__GLIBC__)
struct ether_addr
{
u_char ether_addr_octet[6];
};
#endif
#endif
/*
* ARP packet header prototype. Too many O/S's define this differently.
* Easy enough to solve that and define it here.
*/
struct libnet_arp_hdr
{
u_short ar_hrd; /* format of hardware address */
#define ARPHRD_ETHER 1 /* ethernet hardware format */
u_short ar_pro; /* format of protocol address */
u_char ar_hln; /* length of hardware address */
u_char ar_pln; /* length of protocol addres */
u_short ar_op; /* operation type */
#define ARPOP_REQUEST 1 /* req to resolve address */
#define ARPOP_REPLY 2 /* resp to previous request */
#define ARPOP_REVREQUEST 3 /* req protocol address given hardware */
#define ARPOP_REVREPLY 4 /* resp giving protocol address */
#define ARPOP_INVREQUEST 8 /* req to identify peer */
#define ARPOP_INVREPLY 9 /* resp identifying peer */
/*
* These should implementation defined but I've hardcoded eth/IP.
*/
u_char ar_sha[6]; /* sender hardware address */
u_char ar_spa[4]; /* sender protocol address */
u_char ar_tha[6]; /* target hardware address */
u_char ar_tpa[4]; /* target protocol address */
};
/*
* Base DNS header.
*/
struct libnet_dns_hdr
{
u_short id; /* DNS packet ID */
u_short flags; /* DNS flags */
u_short num_q; /* Number of questions */
u_short num_answ_rr; /* Number of answer resource records */
u_short num_auth_rr; /* Number of authority resource records */
u_short num_addi_rr; /* Number of additional resource records */
};
/*
* Base RIP (routing information protocol) header.
*/
struct libnet_rip_hdr
{
u_char cmd; /* RIP command */
#define RIPCMD_REQUEST 1 /* want info */
#define RIPCMD_RESPONSE 2 /* responding to request */
#define RIPCMD_TRACEON 3 /* turn tracing on */
#define RIPCMD_TRACEOFF 4 /* turn it off */
#define RIPCMD_POLL 5 /* like request, but anyone answers */
#define RIPCMD_POLLENTRY 6 /* like poll, but for entire entry */
#define RIPCMD_MAX 7
u_char ver; /* RIP version */
#define RIPVER_0 0
#define RIPVER_1 1
#define RIPVER_2 2
u_short rd; /* Zero (v1) or Routing Domain (v2) */
u_short af; /* Address family */
u_short rt; /* Zero (v1) or Route Tag (v2) */
u_long addr; /* IP address */
u_long mask; /* Zero (v1) or Subnet Mask (v2) */
u_long next_hop; /* Zero (v1) or Next hop IP address (v2) */
u_long metric; /* Metric */
};
/*
* VRRP packet header prototype.
*/
#ifndef IPPROTO_VRRP
#define IPPROTO_VRRP 112
#endif
struct libnet_vrrp_hdr
{
#if (LIBNET_LIL_ENDIAN)
u_char vrrp_v:4, /* protocol version */
vrrp_t:4; /* packet type */
#endif
#if (LIBNET_BIG_ENDIAN)
u_char vrrp_t:4, /* packet type */
vrrp_v:4; /* protocol version */
#endif
#define LIBNET_VRRP_TYPE_ADVERT 0x1
u_char vrrp_vrouter_id; /* virtual router id */
u_char vrrp_priority; /* priority */
u_char vrrp_ip_count; /* number of IP addresses */
u_char vrrp_auth_type; /* authorization type */
#define LIBNET_VRRP_AUTH_NONE 0x1
#define LIBNET_VRRP_AUTH_PASSWD 0x2
#define LIBNET_VRRP_AUTH_IPAH 0x3
u_char vrrp_advert_int; /* advertisement interval */
u_short vrrp_sum; /* checksum */
};
#if 0
struct libnet_snmp_hdr
{
/* ASN.1 BER support first */
};
#endif
/*
* TCP options structure.
*/
struct tcpoption
{
u_char tcpopt_list[MAX_IPOPTLEN];
};
#ifdef __linux__
/*
* Linux has a radically different IP options structure from BSD.
*/
struct ipoption
{
struct in_addr ipopt_dst; /* first-hop dst if source routed */
char ipopt_list[MAX_IPOPTLEN]; /* options proper */
};
#endif
#endif /* __LIBNET_HEADERS_H */
/* EOF */

View File

@ -0,0 +1,146 @@
/*
* $Id: libnet-macros.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-macros.h - Network routine library macro header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_MACROS_H
#define __LIBNET_MACROS_H
/*
* for libnet_hostlookup
*/
#define LIBNET_DONT_RESOLVE 0
#define LIBNET_RESOLVE 1
/*
* prand constants
*/
#define LIBNET_PR2 0
#define LIBNET_PR8 1
#define LIBNET_PR16 2
#define LIBNET_PRu16 3
#define LIBNET_PR32 4
#define LIBNET_PRu32 5
#define LIBNET_PRAND_MAX 0xffffffff
/*
* Concession to legacy naming scheme
*/
#define PR2 LIBNET_PR2
#define PR8 LIBNET_PR8
#define PR16 LIBNET_PR16
#define PRu16 LIBNET_PRu16
#define PR32 LIBNET_PR32
#define PRu32 LIBNET_PRu32
#define PRAND_MAX LIBNET_PRAND_MAX
/*
* Misc packet sizes for malloc
*/
#define LIBNET_PACKET LIBNET_IP_H + LIBNET_TCP_H /* IP, UDP or TCP */
#define LIBNET_OPTS 0x34 /* options! options! options! */
#define LIBNET_MAX_PACKET 0xffff /* as big as we can get */
/*
* Error handling constants.
*/
#define LIBNET_ERR_WARNING 1
#define LIBNET_ERR_CRITICAL 2
#define LIBNET_ERR_FATAL 3
/*
* Concession to legacy naming scheme
*/
#define LN_ERR_WARNING LIBNET_ERR_WARNING
#define LN_ERR_CRITICAL LIBNET_ERR_CRITICAL
#define LN_ERR_FATAL LIBNET_ERR_FATAL
#define LIBNET_ERRBUF_SIZE 256
/*
* Some BSD variants have this endianess problem.
*/
#if (LIBNET_BSD_BYTE_SWAP)
#define FIX(n) ntohs(n)
#define UNFIX(n) htons(n)
#else
#define FIX(n) (n)
#define UNFIX(n) (n)
#endif
/*
* Arena stuff
*/
#define LIBNET_GET_ARENA_SIZE(a) (a.size)
#define LIBNET_GET_ARENA_REMAINING_BYTES(a) (a.size - a.current)
/*
* Checksum stuff
*/
#define LIBNET_CKSUM_CARRY(x) \
(x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
/*
* OSPF stuff
*/
#define LIBNET_OSPF_AUTHCPY(x,y) memcpy((u_char *)x, (u_char *)y, sizeof(y))
#define LIBNET_OSPF_CKSUMBUF(x,y) memcpy((u_char *)x, (u_char *)y, sizeof(y))
/*
* Not all systems have IFF_LOOPBACK
* Used by if_addr.c
*/
#ifdef IFF_LOOPBACK
#define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
#else
#define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
#endif
#define LIBNET_PRINT_ETH_ADDR(e) \
{ \
int i = 0; \
for (i = 0; i < 6; i++) \
{ \
printf("%x", e.ether_addr_octet[i]); \
if (i != 5) \
{ \
printf(":"); \
} \
} \
printf("\n"); \
}
#endif /* __LIBNET_MACROS_H */
/* EOF */

View File

@ -0,0 +1,394 @@
/*
* $Id: libnet-ospf.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-ospf.h - Network routine library headers header file
*
* Copyright (c) 1999 Andrew Reiter <areiter@bindview.com>
* Bindview Development
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_OSPF_H
#define __LIBNET_OSPF_H
#include <sys/types.h>
/*
* Not all OSes define this in /etc/protocols.. ie, solaris...
*/
#ifndef IPPROTO_OSPF
#define IPPROTO_OSPF 89
#endif
#define IPPROTO_OSPF_LSA 890 /* Made this up. Hope it's unused */
#define OSPFVERSION 2
#define LIBNET_MODX 4102 /* Used in LSA checksum */
/*
* OSPF header lengths.
*/
#define LIBNET_OSPF_H 0x10 /* 16 bytes */
#define LIBNET_HELLO_H 0x18 /* 24 bytes */
#define LIBNET_DBD_H 0x8 /* 8 bytes */
#define LIBNET_LSR_H 0xc /* 12 bytes */
#define LIBNET_LSU_H 0x4 /* 4 bytes */
#define LIBNET_LSA_H 0x14 /* 20 bytes */
#define LIBNET_AUTH_H 0x8 /* 8 bytes */
#define LIBNET_OSPF_CKSUM 0x10 /* 16 bytes */
/*
* Link State packet format lengths.
*/
#define LIBNET_LS_RTR_LEN 0x10 /* 16 bytes */
#define LIBNET_LS_NET_LEN 0x8 /* 8 bytes */
#define LIBNET_LS_SUM_LEN 0xc /* 12 bytes */
#define LIBNET_LS_AS_EXT_LEN 0x10 /* 16 bytes */
/*
* OSPFv2 Packet Header.
*/
struct libnet_ospf_hdr
{
u_char ospf_v; /* version */
u_char ospf_type; /* type */
#define LIBNET_OSPF_UMD 0 /* UMd monitoring packet */
#define LIBNET_OSPF_HELLO 1 /* HELLO packet */
#define LIBNET_OSPF_DBD 2 /* DataBase Description Packet */
#define LIBNET_OSPF_LSR 3 /* Link State Request Packet */
#define LIBNET_OSPF_LSU 4 /* Link State Update Packet */
#define LIBNET_OSPF_LSA 5 /* Link State Acknowledgement Packet */
u_short ospf_len; /* length */
struct in_addr ospf_rtr_id; /* source router ID */
struct in_addr ospf_area_id; /* roam ID */
u_short ospf_cksum; /* checksum */
u_short ospf_auth_type; /* authentication type */
#define LIBNET_OSPF_AUTH_NULL 0 /* Null password */
#define LIBNET_OSPF_AUTH_SIMPLE 1 /* Simple, plaintext, 8 char password */
#define LIBNET_OSPF_AUTH_MD5 2 /* MD5 */
};
/*
* OSPF authentication header.
*/
struct libnet_auth_hdr
{
u_short ospf_auth_null; /* NULL */
u_char ospf_auth_keyid; /* Authentication Key ID */
u_char ospf_auth_len; /* Auth data length */
u_int ospf_auth_seq; /* Cryptographic sequence number */
};
/*
* Options used in multiple OSPF packets.
* More info can be found in section A.2 of RFC 2328.
*/
#define LIBNET_OPT_EBIT 0x02 /* Describes the way AS-external-LSAs are flooded */
#define LIBNET_OPT_MCBIT 0x04 /* Whether or not IP multicast dgrams are fwdd */
#define LIBNET_OPT_NPBIT 0x08 /* Describes handling of type-7 LSAs */
#define LIBNET_OPT_EABIT 0x10 /* rtr's willingness to send/recv EA-LSAs */
#define LIBNET_OPT_DCBIT 0x20 /* Describes handling of demand circuits */
/*
* OSPF HELLO Packet Header.
*/
struct libnet_ospf_hello_hdr
{
struct in_addr hello_nmask; /* Netmask associated with the interface */
u_short hello_intrvl; /* Num of seconds between routers last packet */
u_char hello_opts; /* Options for HELLO packets (look above) */
u_char hello_rtr_pri; /* Router's priority (if 0, can't be backup) */
u_int hello_dead_intvl; /* # of secs a router is silent till deemed down */
struct in_addr hello_des_rtr; /* Designated router on the network */
struct in_addr hello_bkup_rtr; /* Backup router */
struct in_addr hello_nbr; /* neighbor router, memcpy more as needed */
};
/*
* Database Description header.
*/
struct libnet_dbd_hdr
{
u_short dbd_mtu_len; /* Max length of IP dgram that this 'if' can use */
u_char dbd_opts; /* DBD packet options (look above) */
u_char dbd_type; /* Type of exchange occurring (look below) */
#define LIBNET_DBD_IBIT 0x01 /* Init Bit */
#define LIBNET_DBD_MBIT 0x02 /* Says more DBD packets are to come */
#define LIBNET_DBD_MSBIT 0x04 /* If 1, sender is the master in the exchnge */
u_int dbd_seq; /* DBD sequence number */
};
/*
* Used for the LS type field in all LS* headers.
*/
#define LIBNET_LS_TYPE_RTR 1 /* Router-LSA */
#define LIBNET_LS_TYPE_NET 2 /* Network-LSA */
#define LIBNET_LS_TYPE_IP 3 /* Summary-LSA (IP Network) */
#define LIBNET_LS_TYPE_ASBR 4 /* Summary-LSA (ASBR) */
#define LIBNET_LS_TYPE_ASEXT 5 /* AS-External-LSA */
/*
* Link State Request header.
*/
struct libnet_lsr_hdr
{
u_int lsr_type; /* Type of LS being requested (see below) */
u_int lsr_lsid; /* Link State ID */
struct in_addr lsr_adrtr; /* advertising router (memcpy more as needed) */
};
/*
* Link State Update header.
*/
struct libnet_lsu_hdr
{
u_int lsu_num; /* Number of LSAs that will be broadcasted */
};
/*
* Link State Acknowledgement header.
*/
struct libnet_lsa_hdr
{
u_short lsa_age; /* Time in seconds since the LSA was originated */
u_char lsa_opts; /* Look above for OPTS_* */
u_char lsa_type; /* Look below for LS_TYPE_* */
u_int lsa_id; /* Link State ID */
struct in_addr lsa_adv; /* Router ID of Advertising router */
u_int lsa_seq; /* LSA sequence number to detect old/bad ones */
u_char lsa_cksum[2]; /* "Fletcher Checksum" of all fields minus age */
u_short lsa_len; /* Length in bytes including the 20 byte header */
};
/*
* Router LSA data format
*
* Other stuff for TOS can be added for backward compatability, for this
* version, only OSPFv2 is being FULLY supported.
*/
struct libnet_rtr_lsa_hdr
{
u_short rtr_flags; /* Set to help describe packet */
#define LIBNET_RTR_FLAGS_W 0x0100 /* W bit */
#define LIBNET_RTR_FLAGS_E 0x0200 /* E bit */
#define LIBNET_RTR_FLAGS_B 0x0400 /* B bit */
u_short rtr_num; /* Number of links within that packet */
u_int rtr_link_id; /* Describes link_data (look below) */
#define LIBNET_LINK_ID_NBR_ID 1 /* Neighbors router ID, also can be 4 */
#define LIBNET_LINK_ID_IP_DES 2 /* IP address of designated router */
#define LIBNET_LINK_ID_SUB 3 /* IP subnet number */
u_int rtr_link_data; /* Depending on link_id, info is here */
u_char rtr_type; /* Description of router link */
#define LIBNET_RTR_TYPE_PTP 1 /* Point-To-Point */
#define LIBNET_RTR_TYPE_TRANS 2 /* Connection to a "transit network" */
#define LIBNET_RTR_TYPE_STUB 3 /* Connectin to a "stub network" */
#define RTR_TYPE_VRTL 4 /* Connects to a "virtual link" */
u_char rtr_tos_num; /* Number of different TOS metrics for this link */
u_short rtr_metric; /* The "cost" of using this link */
};
/*
* Network LSA data format.
*/
struct libnet_net_lsa_hdr
{
struct in_addr net_nmask; /* Netmask for that network */
u_int net_rtr_id; /* ID of router attached to that network */
};
/*
* Summary LSA data format.
*/
struct libnet_sum_lsa_hdr
{
struct in_addr sum_nmask; /* Netmask of destination IP address */
u_int sum_metric; /* Same as in rtr_lsa (&0xfff to use last 24bit) */
u_int sum_tos_metric; /* first 8bits are TOS, 24bits are TOS Metric */
};
/*
* AS External LSA data format.
* & 0xfff logic operator for as_metric to get last 24bits.
*/
struct libnet_as_lsa_hdr
{
struct in_addr as_nmask; /* Netmask for advertised destination */
u_int as_metric; /* May have to set E bit in first 8bits */
#define LIBNET_AS_E_BIT_ON 0x80000000 /* as_metric */
struct in_addr as_fwd_addr; /* Forwarding address */
u_int as_rte_tag; /* External route tag */
};
int
libnet_build_ospf(
u_short,
u_char,
u_long,
u_long,
u_short,
const char *,
int,
u_char *
);
int
libnet_build_ospf_hello(
u_long,
u_short,
u_char,
u_char,
u_int,
u_long,
u_long,
u_long,
const char *,
int,
u_char *
);
int
libnet_build_ospf_dbd(
u_short,
u_char,
u_char,
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsr(
u_int,
u_int,
u_long,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsu(
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa(
u_short,
u_char,
u_char,
u_int,
u_long,
u_int,
u_short,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_rtr(
u_short,
u_short,
u_int,
u_int,
u_char,
u_char,
u_short,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_net(
u_long,
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_sum(
u_long,
u_int,
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_as(
u_long,
u_int,
u_long,
u_int,
const char *,
int,
u_char *
);
void
libnet_ospf_lsa_checksum(
u_char *,
int
);
#endif /* __LIBNET_OSPF_H */

View File

@ -0,0 +1,84 @@
/*
* $Id: libnet-structures.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-structures.h - Network routine library structures header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_STRUCTURES_H
#define __LIBNET_STRUCTURES_H
/*
* Port list chain structure
*/
struct libnet_plist_chain
{
u_short node; /* node number */
u_short bport; /* beggining port */
u_short eport; /* terminating port */
u_char id; /* global array offset */
struct libnet_plist_chain *next; /* next node in the list */
};
/*
* Low level packet interface struct
*/
struct libnet_link_int
{
int fd; /* link layer file descriptor */
int linktype; /* link type */
int linkoffset; /* link header size (offset till network layer) */
u_char *device; /* device name */
};
/*
* Arena structure.
*/
struct libnet_arena
{
int tag; /* arena tag */
u_char *memory_pool; /* the memory */
u_long current; /* the current amount of memory allocated */
u_long size; /* the size of the pool in bytes */
};
/*
* Interface selection stuff
*/
struct libnet_ifaddr_list
{
u_long addr;
char *device;
};
#endif /* __LIBNET_STRUCTURES_H */
/* EOF */

View File

@ -0,0 +1,27 @@
//For Visual C++ usage
/*
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__83F96D0E_074B_4A74_91DB_10A69F2F3871__INCLUDED_)
#define AFX_STDAFX_H__83F96D0E_074B_4A74_91DB_10A69F2F3871__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000