ocs init
This commit is contained in:
95
plat/radius/Makefile
Normal file
95
plat/radius/Makefile
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile for module Version : V1.4 ##
|
||||
## ##
|
||||
## Created : Wei Liu 07/04/11 ##
|
||||
## Revision: [Last]Wei Liu 07/06/18 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project correlation(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## MODULE= [Module Name]
|
||||
## TYPE = app/plat => Module Type
|
||||
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
|
||||
|
||||
## BUILD = lib/exef => Output file format
|
||||
## CFG = debug/release => Build Configuration
|
||||
|
||||
## SRC_PATH = [Source file path]
|
||||
## INC_PATH = [Include file path]
|
||||
## APP_PATH = [App Module path]
|
||||
## PLT_PATH = [Plat Module path]
|
||||
|
||||
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
|
||||
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
|
||||
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
|
||||
|
||||
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
|
||||
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
|
||||
## snmp iptrans debug sccp public
|
||||
##
|
||||
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
|
||||
## LIB_ADD e.g. = -liba3a8 -lm
|
||||
|
||||
## OBJ_ADD = [Extend third party object files needed]
|
||||
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
|
||||
MODULE = radius
|
||||
TYPE = plat
|
||||
|
||||
DBUG_FLAGS_ADD =
|
||||
RELS_FLAGS_ADD =
|
||||
|
||||
##Default commonly as below
|
||||
|
||||
BUILD = lib
|
||||
CFG = debug
|
||||
|
||||
PLT_LIB =
|
||||
APP_LIB =
|
||||
LIB_ADD =
|
||||
|
||||
SRC_PATH = ./src
|
||||
INC_PATH = ./src/include
|
||||
PLT_PATH = ../../plat
|
||||
APP_PATH = ../../app
|
||||
|
||||
OBJ_ADD =
|
||||
TEST_OBJ_PATH = ../../obj
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make configuration(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## CCFLAG_SWITCH = on/off => gcc flag show on/off
|
||||
## COVER_NEED = yes/no => PTF cover report needed
|
||||
## COVER_REPORT_PATH = [path ] => PTF cover report path
|
||||
|
||||
CCFLAG_SWITCH = off
|
||||
COVER_NEED = no
|
||||
COVER_REPORT_PATH = ./output
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## include makefile.rules (Do not change)
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.rules
|
||||
11
plat/radius/src/include/radius.h
Normal file
11
plat/radius/src/include/radius.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _RADIUS_H
|
||||
#define _RADIUS_H
|
||||
|
||||
#include "./radius_pub.h"
|
||||
|
||||
int radius_init(void);
|
||||
void radius_timer(void);
|
||||
int radius_bind(RADIUS_SAP *sap);
|
||||
|
||||
#endif
|
||||
|
||||
346
plat/radius/src/include/radius_const.h
Normal file
346
plat/radius/src/include/radius_const.h
Normal file
@@ -0,0 +1,346 @@
|
||||
#ifndef _RADIUS_CONST_H
|
||||
#define _RADIUS_CONST_H
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_SHARE_KEY 128
|
||||
#define RADIUS_MAX_LEN_OF_PASSWORD 128
|
||||
|
||||
#define RADIUS_MAX_NUM_OF_NAS 64
|
||||
|
||||
#define RADIUS_ACCESS_PORT 1812
|
||||
#define RADIUS_ACCOUNTING_PORT 1813
|
||||
#define RADIUS_DISCONNECT_PORT 3799
|
||||
|
||||
#define RADIUS_MAX_NUM_OF_SAP 1
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_USER_NAME 16
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_IMSI 16
|
||||
|
||||
#define RADIUS_RECV_MSG_FLAG 0
|
||||
#define RADIUS_SEND_MSG_FLAG 1
|
||||
|
||||
#define RADIUS_PID_TYPE_IND 1
|
||||
#define RADIUS_PID_TYPE_REQ 2
|
||||
|
||||
#define RADIUS_MAX_NUM_OF_ATTRIBUTE 256
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_MSG_TYEP 32
|
||||
|
||||
#define RADIUS_MAX_UDP_MSG_GET_TIMES 32
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_ATTR 255
|
||||
#define RADIUS_TS_VALUE_LEN 253
|
||||
#define RADIUS_NOWSMS_MAX_LEN_OF_PER_CALLED 250
|
||||
#define RADIUS_VALUE_LEN 4
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_TEMP_BUF 256
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_MSG 1500
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_UDP_MSG 1500
|
||||
|
||||
#define RADIUS_MAX_LEN_FOR_OCTET_STR 4
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_AUTH 16
|
||||
|
||||
#define RADIUS_MAX_NUM_OF_PID 8192
|
||||
|
||||
#define RADIUS_MAX_ASCITMP_LEN 4096
|
||||
#define RADIUS_MAX_ASCIIOUT_LEN 4096
|
||||
#define RADIUS_MAX_ASCIIIN_LEN 4096
|
||||
|
||||
#define RADIUS_MONITOR_NONE 0x0000
|
||||
#define RADIUS_MONITOR_ERROR 0x0001
|
||||
#define RADIUS_MONITOR_WARN 0x0002
|
||||
#define RADIUS_MONITOR_EVENT 0x0004
|
||||
#define RADIUS_MONITOR_ACCESS_MSG 0x0008
|
||||
#define RADIUS_MONITOR_ACCT_MSG 0x0010
|
||||
#define RADIUS_MONITOR_DISC_MSG 0x0020
|
||||
#define RADIUS_MONITOR_ALL 0xFFFF
|
||||
#define RADIUS_MONITOR_SDRV_MSG (RADIUS_MONITOR_ACCESS_MSG | RADIUS_MONITOR_ACCT_MSG | RADIUS_MONITOR_DISC_MSG)
|
||||
|
||||
#define RADIUS_REQUEST_MSG 1
|
||||
#define RADIUS_RESPONSE_MSG 2
|
||||
|
||||
#define RADIUS_MSG_TYPE_ACCESS_REQUEST 1
|
||||
#define RADIUS_MSG_TYPE_ACCESS_ACCEPT 2
|
||||
#define RADIUS_MSG_TYPE_ACCESS_REJECT 3
|
||||
#define RADIUS_MSG_TYPE_ACCOUNTING_REQUEST 4
|
||||
#define RADIUS_MSG_TYPE_ACCOUNTING_RESPONSE 5
|
||||
#define RADIUS_MSG_TYPE_ACCESS_CHALLENGE 11
|
||||
#define RADIUS_MSG_TYPE_STATUS_SERVER 12
|
||||
#define RADIUS_MSG_TYPE_STATUS_CLIENT 13
|
||||
#define RADIUS_MSG_TYPE_DISCONNECT_REQUEST 40
|
||||
#define RADIUS_MSG_TYPE_DISCONNECT_ACK 41
|
||||
#define RADIUS_MSG_TYPE_DISCONNECT_NAK 42
|
||||
#define RADIUS_MSG_TYPE_COA_REQUEST 43
|
||||
#define RADIUS_MSG_TYPE_COA_ACK 44
|
||||
#define RADIUS_MSG_TYPE_COA_NAK 45
|
||||
|
||||
#define RADIUS_ATTRIBUTE_TYPE_USER_NAME 1
|
||||
#define RADIUS_ATTRIBUTE_TYPE_USER_PASSWORD 2
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CHAP_PASSWORD 3
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NAS_IP_ADDRESS 4
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NAS_PORT 5
|
||||
#define RADIUS_ATTRIBUTE_TYPE_SERVICE_TYPE 6
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_PROTOCOL 7
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_IP_ADDR 8
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_IP_NETMASK 9
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_ROUTING 10
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FILTER_ID 11
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_MTU 12
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_COMPRESSION 13
|
||||
#define RADIUS_ATTRIBUTE_TYPE_LOGIN_IP_HOST 14
|
||||
#define RADIUS_ATTRIBUTE_TYPE_LOGIN_SERVICE 15
|
||||
#define RADIUS_ATTRIBUTE_TYPE_LOGIN_TCP_PORT 16
|
||||
#define RADIUS_ATTRIBUTE_TYPE_17 17
|
||||
#define RADIUS_ATTRIBUTE_TYPE_REPLY_MESSAGE 18
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CALLBACK_NUMBER 19
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CALLBACK_ID 20
|
||||
#define RADIUS_ATTRIBUTE_TYPE_21 21
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_ROUTE 22
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_IPX_NETWORK 23
|
||||
#define RADIUS_ATTRIBUTE_TYPE_STATE 24
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CLASS 25
|
||||
#define RADIUS_ATTRIBUTE_TYPE_VENDOR_SPECIFIC 26
|
||||
#define RADIUS_ATTRIBUTE_TYPE_SESSION_TIMEOUT 27
|
||||
#define RADIUS_ATTRIBUTE_TYPE_IDLE_TIMEOUT 28
|
||||
#define RADIUS_ATTRIBUTE_TYPE_TERMINATION_ACTION 29
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CALLED_STATION_ID 30
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CALLING_STATION_ID 31
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NAS_IDENTIFIER 32
|
||||
#define RADIUS_ATTRIBUTE_TYPE_PROXY_STATE 33
|
||||
#define RADIUS_ATTRIBUTE_TYPE_LOGIN_LAT_SERVICE 34
|
||||
#define RADIUS_ATTRIBUTE_TYPE_LOGIN_LAT_NODE 35
|
||||
#define RADIUS_ATTRIBUTE_TYPE_LOGIN_LAT_GROUP 36
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_APPLETALK_LINK 37
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_APPLETALK_NETWORK 38
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_APPLETALK_ZONE 39
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_STATUS_TYPE 40
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_DELAY_TIME 41
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_INPUT_OCTETS 42
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_OUTPUT_OCTETS 43
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_SESSION_ID 44
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_AUTHENTIC 45
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_SESSION_TIME 46
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_INPUT_PACKETS 47
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_OUTPUT_PACKETS 48
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_TERMINATE_CAUSE 49
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_MULTI_SESSION_ID 50
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_LINK_COUNT 51
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_INPUT_GIGAWORDS 52
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_OUTPUT_GIGAWORDS 53
|
||||
#define RADIUS_ATTRIBUTE_TYPE_EVENT_TIMESTAMP 55
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CHAP_CHALLENGE 60
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NAS_PORT_TYPE 61
|
||||
#define RADIUS_ATTRIBUTE_TYPE_PORT_LIMIT 62
|
||||
#define RADIUS_ATTRIBUTE_TYPE_LOGIN_LAT_PORT 63
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ARAP_PASSWORD 70
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ARAP_FEATURES 71
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ARAP_ZONE_ACCESS 72
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ARAP_SECURITY 73
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ARAP_SECURITY_DATA 74
|
||||
#define RADIUS_ATTRIBUTE_TYPE_PASSWORD_RETRY 75
|
||||
#define RADIUS_ATTRIBUTE_TYPE_PROMPT 76
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CONNECT_INFO 77
|
||||
#define RADIUS_ATTRIBUTE_TYPE_CONFIGURATION_TOKEN 78
|
||||
#define RADIUS_ATTRIBUTE_TYPE_EAP_MESSAGE 79
|
||||
#define RADIUS_ATTRIBUTE_TYPE_MESSAGE_AUTHENTICATOR 80
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ARAP_CHALLENGE_RESPONSE 84
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ACCT_INTERIM_INTERVAL 85
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NAS_PORT_ID 87
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_POOL 88
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ORIGINATING_LINE_INFO 94//not support now
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_INTERFACE_ID 96//not support now
|
||||
#define RADIUS_ATTRIBUTE_TYPE_FRAMED_IPV6_PREFIX 97//not support now
|
||||
#define RADIUS_ATTRIBUTE_TYPE_ERROR_CAUSE 101
|
||||
//non-standard support NOWSMS
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_PREAUTH_TYPE RADIUS_ATTRIBUTE_TYPE_17
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_COUNT_ID_SIZE RADIUS_ATTRIBUTE_TYPE_21
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_TYPE_VALUE_AUTH_SMS 1
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_TYPE_VALUE_ACCOUNT_SMS 2
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_TYPE_VALUE_AUTH_MMS 3
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_TYPE_VALUE_CHARGE_MMS_SEND 4
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_TYPE_VALUE_ACCOUNT_MMS_RETRIEVE 5
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_TYPE_VALUE_AUTH_MMSE 6
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_TYPE_VALUE_CHARGE_MMSE 7
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_SUB_MSGCOUNT 1
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_SUB_MSGID 2
|
||||
#define RADIUS_ATTRIBUTE_TYPE_NOWSMS_SUB_SIZE 3
|
||||
|
||||
#define RADIUS_VENDOR_ID_WIMAX 24757
|
||||
|
||||
#define RADIUS_VENDOR_ID_3GPP 10415
|
||||
#define RADIUS_VENDOR_ID_3GPP2 5535
|
||||
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_IMSI 1
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_CHARGING_ID 2
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_PDP_TYPE 3
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_CG_ADDR 4//charging gateway address
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_NQP 5//negotiated qos profile
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_SGSN_ADDR 6
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_GGSN_ADDR 7
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_IMSI_MCC_MNC 8
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_GGSN_MCC_MNC 9
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_NSAPI 10
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_SSI 11//session stop indicator
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_SM 12//selection mode
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_CC 13//charging characteristics
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_CG_IPV6 14//charging gateway ipv6 not support
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_SGSN_IPV6 15//sgsn ipv6 not support
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_GGSN_IPV6 16//ggsn ipv6 not support
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_IPV6_DNS 17//ipv6 DNS servers not support
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_SGSN_MCC_MNC 18
|
||||
#define RADIUS_VENDOR_TYPE_3GPP_TI 19//teardown indicator
|
||||
|
||||
#define RADIUS_VENDOR_TYPE_3GPP2_STC 88
|
||||
#define RADIUS_VENDOR_TYPE_3GPP2_PPAQ 90
|
||||
#define RADIUS_VENDOR_TYPE_3GPP2_PPAC 91
|
||||
#define RADIUS_VENDOR_TYPE_3GPP2_PTS 98
|
||||
|
||||
#define RADIUS_3GPP2_PPAC_SUBTYPE_AIC 1
|
||||
#define RADIUS_3GPP2_PPAC_SUBTYPE_SFS 2
|
||||
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_QID 1//quota identifier; access request, access accept
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_VQ 2//volume quota; access request, access accept
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_VQO 3//volume quota overflow
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_VT 4//volume threshold; access accept
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_VTO 5//volume threshold overflow
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_DQ 6//duration quota; access request, access accept
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_DT 7//duration threshold; access accept
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_UR 8//update reason; access request
|
||||
#define RADIUS_3GPP2_PPAQ_SUBTYPE_PS 9//prepaid server; access request, access accept
|
||||
|
||||
#define RADIUS_3GPP2_PTS_SUBTYPE_QID 1
|
||||
#define RADIUS_3GPP2_PTS_SUBTYPE_VUATS 2
|
||||
#define RADIUS_3GPP2_PTS_SUBTYPE_VUATSO 3
|
||||
#define RADIUS_3GPP2_PTS_SUBTYPE_TSI 4
|
||||
#define RADIUS_3GPP2_PTS_SUBTYPE_TITSU 5
|
||||
|
||||
#define RADIUS_VENDOR_TYPE_PPAC 35//prepaid accounting capability
|
||||
#define RADIUS_VENDOR_TYPE_STC 36//session termination capability
|
||||
#define RADIUS_VENDOR_TYPE_PPAQ 37//prepaid accouting operate
|
||||
#define RADIUS_VENDOR_TYPE_PTS 38//prepaid tariff switch
|
||||
|
||||
#define RADIUS_PPAC_SUBTYPE_AIC 1
|
||||
|
||||
#define RADIUS_PPAC_AIC_VM 0x00000001//Volume metering supported
|
||||
#define RADIUS_PPAC_AIC_DM 0x00000010//Duration metering supported
|
||||
#define RADIUS_PPAC_AIC_RM 0x00000100//Resource metering supported
|
||||
#define RADIUS_PPAC_AIC_PS 0x00001000//Pools supported
|
||||
#define RADIUS_PPAC_AIC_RGS 0x00010000//Rating groups supported
|
||||
#define RADIUS_PPAC_AIC_MSS 0x00100000//Multi-Services supported
|
||||
#define RADIUS_PPAC_AIC_TSS 0x01000000//Tariff Switch supported
|
||||
#define RADIUS_PPAC_AIC_RESERVED 0x10000000//Reserved*/
|
||||
|
||||
#define RADIUS_PPAQ_SUBTYPE_QID 1//quota identifier; access request, access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_VQ 2//volume quota; access request, access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_VT 3//volume threshold; access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_DQ 4//duration quota; access request, access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_DT 5//duration threshold; access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_RQ 6//resource quota; access request, access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_RT 7//resource threshold; access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_UR 8//update reason; access request
|
||||
#define RADIUS_PPAQ_SUBTYPE_PS 9//prepaid server; access request, access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_SID 10//service id; access request, access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_RGID 11//rating group id; access request, access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_TA 12//termination action; access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_PLID 13//pool id; access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_PM 14//pool multiplier; access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_RA 15//requested action; access request
|
||||
#define RADIUS_PPAQ_SUBTYPE_CBR 16//check balance result; access accept
|
||||
#define RADIUS_PPAQ_SUBTYPE_CI 17//cost information; access accept
|
||||
|
||||
#define RADIUS_PTS_SUBTYPE_VUATS 23//volume used after tariff switch
|
||||
#define RADIUS_PTS_SUBTYPE_TSI 24//tariff switch interval
|
||||
#define RADIUS_PTS_SUBTYPE_TITSU 25//time interval after tariff switch update
|
||||
|
||||
#define RADIUS_PPAQ_UR_PRE_INIT 1
|
||||
#define RADIUS_PPAQ_UR_INIT_REQUEST 2
|
||||
#define RADIUS_PPAQ_UR_THRESHOLD_REACHED 3
|
||||
#define RADIUS_PPAQ_UR_QUOTA_REACHED 4
|
||||
#define RADIUS_PPAQ_UR_TITSU_APPROACHING 5
|
||||
#define RADIUS_PPAQ_UR_REMOTE_DISC 6
|
||||
#define RADIUS_PPAQ_UR_CLIENT_SERVICE_TER 7
|
||||
#define RADIUS_PPAQ_UR_ACCESS_SERVICE_TER 8
|
||||
#define RADIUS_PPAQ_UR_SERVICE_NOT_EST 9
|
||||
#define RADIUS_PPAQ_UR_ONE_TIME_CHARGING 10
|
||||
|
||||
#define RADIUS_PPAQ_TA_TERMINATE 1
|
||||
#define RADIUS_PPAQ_TA_REQUEST_MORE_QUOTA 2
|
||||
#define RADIUS_PPAQ_TA_REDIRCT_FILTER 3
|
||||
|
||||
#define RADIUS_PPAQ_RA_BALANCE_CHECK 1
|
||||
#define RADIUS_PPAQ_RA_PRICE_ENQUIRY 2
|
||||
|
||||
#define RADIUS_PPAQ_CBR_SUCCESS 0
|
||||
#define RADIUS_PPAQ_CBR_FAILURE 1
|
||||
|
||||
#define RADIUS_MAX_NUM_OF_FRAMED_COMPRESSION 4
|
||||
#define RADIUS_MAX_NUM_OF_LOGIN_IP_HOST 4
|
||||
#define RADIUS_MAX_NUM_OF_VENDOR_SPECIFIC 32
|
||||
#define RADIUS_MAX_NUM_OF_FILTER_ID 4
|
||||
#define RADIUS_MAX_NUM_OF_REPLY_MESSAGE 4
|
||||
#define RADIUS_MAX_NUM_OF_FRAMED_ROUTE 4
|
||||
#define RADIUS_MAX_NUM_OF_CLASS 4
|
||||
#define RADIUS_MAX_NUM_OF_FRAMED_APPLETALK_NETWORK 4
|
||||
#define RADIUS_MAX_NUM_OF_ACCT_MULTI_SESSION_ID 4
|
||||
#define RADIUS_MAX_NUM_OF_ACCT_LINK_COUNT 4
|
||||
#define RADIUS_MAX_NUM_OF_PROXY_STATE 4
|
||||
#define RADIUS_MAX_NUM_OF_EAP_MESSAGE 4
|
||||
#define RADIUS_MAX_NUM_OF_ARAP_SECURITY_DATA 4
|
||||
#define RADIUS_MAX_NUM_OF_CONFIGURATION_TOKEN 4
|
||||
#define RADIUS_MAX_NUM_OF_ERROR_CAUSE 4
|
||||
#define RADIUS_MAX_NUM_OF_NOWSMS_CALLED_ID 100
|
||||
#define RADIUS_MAX_NUM_OF_NOWSMS_CALLED_LIST 1300
|
||||
|
||||
#define RADIUS_TIMER_ONE_SECOND 100
|
||||
#define RADIUS_TIMER_16S (16 * RADIUS_TIMER_ONE_SECOND)
|
||||
#define RADIUS_TIMER_32S (32 * RADIUS_TIMER_ONE_SECOND)
|
||||
#define RADIUS_RETRANS_TIMER (8 * RADIUS_TIMER_ONE_SECOND)
|
||||
|
||||
#define RADIUS_PID_REQ_STATE_IDLE 0
|
||||
#define RADIUS_PID_REQ_STATE_WAIT_FOR_PEER_RESP 1
|
||||
#define RADIUS_PID_REQ_STATE_TERMINATE 2
|
||||
|
||||
#define RADIUS_PID_IND_STATE_IDLE 0
|
||||
#define RADIUS_PID_IND_STATE_WAIT_FOR_USER_RESP 1
|
||||
#define RADIUS_PID_IND_STATE_WAIT_FOR_TERMINATE 2
|
||||
#define RADIUS_PID_IND_STATE_TERMINATE 3
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_RESULT 128
|
||||
#define RADIUS_MAX_LEN_OF_IN 16
|
||||
|
||||
#define RADIUS_MAX_LEN_MD5 16
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_ENCRYPT_PASSWORD 128
|
||||
|
||||
#define RADIUS_SERVICE_TYPE_LOGIN 1
|
||||
#define RADIUS_SERVICE_TYPE_FRAMED 2
|
||||
#define RADIUS_SERVICE_TYPE_CALLBACK_LOGIN 3
|
||||
#define RADIUS_SERVICE_TYPE_CALLBACK_FRAMED 4
|
||||
#define RADIUS_SERVICE_TYPE_OUTBOUND 5
|
||||
#define RADIUS_SERVICE_TYPE_ADMIN 6
|
||||
#define RADIUS_SERVICE_TYPE_NAS_PROMPT 7
|
||||
#define RADIUS_SERVICE_TYPE_AUTHENTICATE_ONLY 8
|
||||
#define RADIUS_SERVICE_TYPE_CALLBACK_NAS_PROMPT 9
|
||||
#define RADIUS_SERVICE_TYPE_CALL_CHECK 10
|
||||
#define RADIUS_SERVICE_TYPE_CALLBACK_ADMIN 11
|
||||
#define RADIUS_SERVICE_TYPE_AUTHORIZE_ONLY 17
|
||||
|
||||
#define RADIUS_ACCT_STATUS_TYPE_START 1
|
||||
#define RADIUS_ACCT_STATUS_TYPE_STOP 2
|
||||
#define RADIUS_ACCT_STATUS_TYPE_INTERIM_UPDATE 3
|
||||
#define RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_ON 7
|
||||
#define RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF 8
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_MCC 3
|
||||
#define RADIUS_MAX_LEN_OF_MNC 3
|
||||
|
||||
#define RADIUS_ARICENT_VOLUME_INT 1
|
||||
#define RADIUS_ARICENT_VOLUME_EXP 2
|
||||
|
||||
#define RADIUS_MAX_LEN_OF_MESSAGE_AUTH_ATTR 16
|
||||
|
||||
#endif
|
||||
|
||||
14
plat/radius/src/include/radius_debug.h
Normal file
14
plat/radius/src/include/radius_debug.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _RADIUS_DEBUG_H
|
||||
#define _RADIUS_DEBUG_H
|
||||
|
||||
int radius_debug_set(void);
|
||||
|
||||
void radius_mon(void);
|
||||
|
||||
int radius_log_err(const char *fmt, ...);
|
||||
int radius_log_event(const char *fmt, ...);
|
||||
int radius_log_warn(const char *fmt, ...);
|
||||
int radius_log_send_recv_msg(BYTE *msg, int len, RADIUS_ADDR *addr, BYTE msg_type, BYTE flag);
|
||||
|
||||
#endif
|
||||
|
||||
42
plat/radius/src/include/radius_def.h
Normal file
42
plat/radius/src/include/radius_def.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef _RADIUS_DEF_H
|
||||
#define _RADIUS_DEF_H
|
||||
/*
|
||||
BYTE RADIUS_Version[4] = {1, 0, 0, 2};
|
||||
|
||||
int radius_udp_access_socket_fd;
|
||||
|
||||
int radius_udp_account_socket_fd;
|
||||
|
||||
int radius_udp_disconnect_socket_fd;
|
||||
|
||||
int radius_pid_select;
|
||||
|
||||
BYTE radius_access_id_select;
|
||||
BYTE radius_accounting_id_select;
|
||||
BYTE radius_disconnect_id_select;
|
||||
|
||||
RADIUS_MSG radius_msg_pdu;
|
||||
|
||||
RADIUS_PID radius_pid[RADIUS_MAX_NUM_OF_PID];
|
||||
|
||||
BYTE radius_udp_msg_recv_buf[RADIUS_MAX_LEN_OF_UDP_MSG];
|
||||
|
||||
WORD radius_mon_flag;
|
||||
|
||||
BYTE radius_asci_tmp_buf[RADIUS_MAX_ASCITMP_LEN];
|
||||
BYTE radius_asci_out_buf[RADIUS_MAX_ASCIIOUT_LEN];
|
||||
BYTE radius_asci_in_buf[RADIUS_MAX_ASCIIIN_LEN];
|
||||
|
||||
char radius_msg_type_str[RADIUS_MAX_LEN_OF_MSG_TYEP];
|
||||
|
||||
RADIUS_ATTR_PARSE_FUNCTION radius_attr_parse_function[RADIUS_MAX_NUM_OF_ATTRIBUTE];
|
||||
|
||||
RADIUS_SAP radius_sap[RADIUS_MAX_NUM_OF_SAP];
|
||||
|
||||
RADIUS_NAS_INFO radius_nas_info[RADIUS_MAX_NUM_OF_NAS];*/
|
||||
|
||||
//BYTE radius_nas_share_key[RADIUS_MAX_NUM_OF_SAP][RADIUS_MAX_LEN_OF_SHARE_KEY];
|
||||
//BYTE radius_nas_password[RADIUS_MAX_NUM_OF_SAP][RADIUS_MAX_LEN_OF_PASSWORD];
|
||||
|
||||
#endif
|
||||
|
||||
41
plat/radius/src/include/radius_ext.h
Normal file
41
plat/radius/src/include/radius_ext.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef _RADIUS_EXT_H
|
||||
#define _RADIUS_EXT_H
|
||||
|
||||
extern BYTE RADIUS_Version[4];
|
||||
|
||||
extern int radius_udp_access_socket_fd;
|
||||
|
||||
extern int radius_udp_account_socket_fd;
|
||||
|
||||
extern int radius_udp_disconnect_socket_fd;
|
||||
|
||||
extern int radius_pid_select;
|
||||
|
||||
extern BYTE radius_access_id_select;
|
||||
extern BYTE radius_accounting_id_select;
|
||||
extern BYTE radius_disconnect_id_select;
|
||||
|
||||
extern RADIUS_MSG radius_msg_pdu;
|
||||
|
||||
extern RADIUS_PID radius_pid[RADIUS_MAX_NUM_OF_PID];
|
||||
|
||||
extern BYTE radius_udp_msg_recv_buf[RADIUS_MAX_LEN_OF_UDP_MSG];
|
||||
|
||||
extern WORD radius_mon_flag;
|
||||
|
||||
extern BYTE radius_asci_tmp_buf[RADIUS_MAX_ASCITMP_LEN];
|
||||
extern BYTE radius_asci_out_buf[RADIUS_MAX_ASCIIOUT_LEN];
|
||||
extern BYTE radius_asci_in_buf[RADIUS_MAX_ASCIIIN_LEN];
|
||||
|
||||
extern char radius_msg_type_str[RADIUS_MAX_LEN_OF_MSG_TYEP];
|
||||
|
||||
extern RADIUS_ATTR_PARSE_FUNCTION radius_attr_parse_function[RADIUS_MAX_NUM_OF_ATTRIBUTE];
|
||||
|
||||
extern RADIUS_SAP radius_sap[RADIUS_MAX_NUM_OF_SAP];
|
||||
|
||||
extern RADIUS_NAS_INFO radius_nas_info[RADIUS_MAX_NUM_OF_NAS];
|
||||
|
||||
//extern BYTE radius_nas_share_key[RADIUS_MAX_NUM_OF_SAP][RADIUS_MAX_LEN_OF_SHARE_KEY];
|
||||
//extern BYTE radius_nas_password[RADIUS_MAX_NUM_OF_SAP][RADIUS_MAX_LEN_OF_PASSWORD];
|
||||
|
||||
#endif
|
||||
8
plat/radius/src/include/radius_fsm.h
Normal file
8
plat/radius/src/include/radius_fsm.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _RADIUS_FSM_H
|
||||
#define _RADIUS_FSM_H
|
||||
|
||||
int radius_fsm(void);
|
||||
int radius_p_fsm(int pid);
|
||||
|
||||
#endif
|
||||
|
||||
33
plat/radius/src/include/radius_function.h
Normal file
33
plat/radius/src/include/radius_function.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _RADIUS_FUNCTION_H
|
||||
#define _RADIUS_FUNCTION_H
|
||||
|
||||
RADIUS_PID *radius_get_pid_ptr(int pid);
|
||||
int radius_init_pid(int pid);
|
||||
int radius_init_socket(void);
|
||||
|
||||
int radius_attr_parse_init();
|
||||
int radius_send_msg(int pid);
|
||||
|
||||
int radius_set_udp_dest_addr(struct sockaddr_in *dst_addr, RADIUS_ADDR *addr);
|
||||
int radius_get_sock_fd_according_msg_type(BYTE msg_type);
|
||||
|
||||
int radius_msg_to_fmt(const BYTE *bcd, int bcd_len, char *str, int str_buff_size);
|
||||
|
||||
int radius_authenticate_nas(BYTE *authenticator, RADIUS_NAS_INFO *nas_info_ptr, RADIUS_ACCESS_REQUEST * access_request, BYTE *msg, int msg_len, int msg_auth_attr_offset);
|
||||
int radius_calculate_authenticator(BYTE *rep_auth, const BYTE *msg, int msg_len, BYTE *share_key);
|
||||
|
||||
RADIUS_NAS_INFO *radius_get_nas_info_ptr(int id);
|
||||
int radius_accord_ip_search_nas_info(DWORD nas_ip);
|
||||
|
||||
int radius_udp_msg_handling(BYTE *msg, int len, RADIUS_ADDR *addr, int nas_id);
|
||||
|
||||
int radius_encode_access_request(BYTE sap_index, BYTE *identifier, BYTE *authenticator, BYTE *msg, RADIUS_ACCESS_REQUEST *access_request, int nas_id);
|
||||
int radius_encode_access_accept(BYTE identifier, BYTE *request_authenticator, BYTE *msg, RADIUS_ACCESS_ACCEPT *access_accept, int nas_id);
|
||||
int radius_encode_access_reject(BYTE identifier, BYTE *request_authenticator, BYTE *msg, RADIUS_ACCESS_REJECT *access_reject, int nas_id);
|
||||
int radius_encode_accounting_response(BYTE identifier, BYTE *request_authenticator, BYTE *msg, RADIUS_ACCOUNTING_RESPONSE *accounting_response, int nas_id);
|
||||
int radius_encode_disconnect_request(BYTE *identifier, BYTE *authenticator, BYTE *msg, RADIUS_DISCONNECT_REQUEST *disconnect_request, int nas_id);
|
||||
|
||||
int radius_get_pid();
|
||||
|
||||
#endif
|
||||
|
||||
26
plat/radius/src/include/radius_if.h
Normal file
26
plat/radius/src/include/radius_if.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _RADIUS_IF_H
|
||||
#define _RADIUS_IF_H
|
||||
|
||||
#include "./radius_pub.h"
|
||||
|
||||
typedef struct _RADIUS_NAS_INFORMATION
|
||||
{
|
||||
DWORD nas_ip;
|
||||
BYTE share_key[RADIUS_MAX_LEN_OF_SHARE_KEY];
|
||||
BYTE password[RADIUS_MAX_LEN_OF_PASSWORD];
|
||||
}__attribute__((packed)) RADIUS_NAS_INFORMATION;//be used for up layer interface struct
|
||||
|
||||
int radius_set_nas_info(BYTE sap_index, BYTE id, RADIUS_NAS_INFORMATION *nas_information);
|
||||
int radius_delet_nas_info(BYTE sap_index, BYTE id);
|
||||
|
||||
int radius_send_access_request(BYTE sap_index, WORD usr_pid, RADIUS_MSG *msg_pdu, RADIUS_ADDR *addr);
|
||||
int radius_send_access_accept(BYTE sap_index, WORD pid, WORD usr_pid, RADIUS_MSG *msg_pdu);
|
||||
int radius_send_access_reject(BYTE sap_index, WORD pid, WORD usr_pid, RADIUS_MSG *msg_pdu);
|
||||
int radius_send_accounting_response(BYTE sap_index, WORD pid, WORD usr_pid, RADIUS_MSG *msg_pdu);
|
||||
int radius_send_disconnect_request(BYTE sap_index, WORD usr_pid, RADIUS_MSG *msg_pdu, RADIUS_ADDR *addr);
|
||||
|
||||
int radius_calculate_chap_password(BYTE *auth, BYTE chap_id, const BYTE *password, const BYTE *chap_challenge, int chap_len);
|
||||
int radius_encrypt_user_password(BYTE *encrypt_password, BYTE *password, BYTE *authenticator, BYTE *share_key);
|
||||
|
||||
#endif
|
||||
|
||||
6
plat/radius/src/include/radius_inc.h
Normal file
6
plat/radius/src/include/radius_inc.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _RADIUS_INC_H
|
||||
#define _RADIUS_INC_H
|
||||
#include "../../../debug/src/include/debug.h"
|
||||
#include "../../../public/src/include/pub_inet.h"
|
||||
|
||||
#endif
|
||||
85
plat/radius/src/include/radius_md5.h
Normal file
85
plat/radius/src/include/radius_md5.h
Normal file
@@ -0,0 +1,85 @@
|
||||
//md5.h
|
||||
/***********************************************************************/
|
||||
/** md5.h -- header file for implementation of MD5 **/
|
||||
/** RSA Data Security, Inc. MD5 Message-Digest Algorithm **/
|
||||
/** Created: 2/17/90 RLR **/
|
||||
/** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **/
|
||||
/** Revised (for MD5): RLR 4/27/91 **/
|
||||
/** -- G modified to have y&~z instead of y&z **/
|
||||
/** -- FF, GG, HH modified to add in last register done **/
|
||||
/** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **/
|
||||
/** -- distinct additive constant for each step **/
|
||||
/** -- round 4 added, working mod 7 **/
|
||||
/***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
/** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **/
|
||||
/** **/
|
||||
/** License to copy and use this software is granted provided that **/
|
||||
/** it is identified as the "RSA Data Security, Inc. MD5 Message- **/
|
||||
/** Digest Algorithm" in all material mentioning or referencing this **/
|
||||
/** software or this function. **/
|
||||
/** **/
|
||||
/** License is also granted to make and use derivative works **/
|
||||
/** provided that such works are identified as "derived from the RSA **/
|
||||
/** Data Security, Inc. MD5 Message-Digest Algorithm" in all **/
|
||||
/** material mentioning or referencing the derived work. **/
|
||||
/** **/
|
||||
/** RSA Data Security, Inc. makes no representations concerning **/
|
||||
/** either the merchantability of this software or the suitability **/
|
||||
/** of this software for any particular purpose. It is provided "as **/
|
||||
/** is" without express or implied warranty of any kind. **/
|
||||
/** **/
|
||||
/** These notices must be retained in any copies of any part of this **/
|
||||
/** documentation and/or software. **/
|
||||
/***********************************************************************/
|
||||
|
||||
#ifndef _RADIUS_MD5_H
|
||||
#define _RADIUS_MD5_H
|
||||
|
||||
/* typedef a 32-bit type */
|
||||
//typedef unsigned long int UINT4;
|
||||
typedef unsigned int UINT4;
|
||||
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
/* Data structure for MD5 (Message-Digest) computation */
|
||||
typedef struct _MD5_CTX
|
||||
{
|
||||
UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
|
||||
UINT4 buf[4]; /* scratch buffer */
|
||||
unsigned char in[64]; /* input buffer */
|
||||
unsigned char digest[16]; /* actual digest after MD5Final call */
|
||||
} MD5_CTX;
|
||||
|
||||
void radius_MD5Init (MD5_CTX *);
|
||||
void radius_MD5Update (MD5_CTX *,unsigned char *,unsigned int);
|
||||
void radius_MD5Final (MD5_CTX *);
|
||||
void radius_MD5Transform(UINT4 *,UINT4 *);
|
||||
void radius_get_md5_str(char *dest, char *org, int len);
|
||||
void radius_get_md5_hex(char *dest, char *org, int len);
|
||||
void radius_get_hmac_md5_hex(BYTE *dest, BYTE *org, int org_len, BYTE *key, int key_len);
|
||||
|
||||
#endif
|
||||
/***********************************************************************/
|
||||
/** End of md5.h **/
|
||||
/***********************************************************************/
|
||||
|
||||
66
plat/radius/src/include/radius_pub.h
Normal file
66
plat/radius/src/include/radius_pub.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef _RADIUS_PUB__H
|
||||
#define _RADIUS_PUB__H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#include <netdb.h>
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stropts.h>
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
#include <termio.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/io.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/msg.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#ifndef _T_BYTE
|
||||
#define _T_BYTE
|
||||
typedef unsigned char BYTE;
|
||||
#endif
|
||||
|
||||
#ifndef _T_WORD
|
||||
#define _T_WORD
|
||||
typedef unsigned short WORD;
|
||||
#endif
|
||||
|
||||
#ifndef _T_DWORD
|
||||
#define _T_DWORD
|
||||
typedef unsigned int DWORD;
|
||||
#endif
|
||||
|
||||
#include "./radius_const.h"
|
||||
#include "./radius_struct.h"
|
||||
#include "./radius_ext.h"
|
||||
#include "./radius.h"
|
||||
#include "./radius_md5.h"
|
||||
#include "./radius_function.h"
|
||||
#include "./radius_fsm.h"
|
||||
#include "./radius_transport.h"
|
||||
#include "./radius_debug.h"
|
||||
#include "./radius_if.h"
|
||||
|
||||
#endif
|
||||
|
||||
1433
plat/radius/src/include/radius_struct.h
Normal file
1433
plat/radius/src/include/radius_struct.h
Normal file
File diff suppressed because it is too large
Load Diff
8
plat/radius/src/include/radius_transport.h
Normal file
8
plat/radius/src/include/radius_transport.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _RADIUS_TRANSPORT_H
|
||||
#define _RADIUS_TRANSPORT_H
|
||||
|
||||
int radius_recv_udp_msg(void);
|
||||
int radius_send_udp_msg(int pid);
|
||||
|
||||
#endif
|
||||
|
||||
121
plat/radius/src/radius.c
Normal file
121
plat/radius/src/radius.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "./include/radius_pub.h"
|
||||
#include "./include/radius_def.h"
|
||||
|
||||
// fix multiple definition====================================
|
||||
BYTE RADIUS_Version[4] = {1, 0, 0, 2};
|
||||
|
||||
int radius_udp_access_socket_fd;
|
||||
|
||||
int radius_udp_account_socket_fd;
|
||||
|
||||
int radius_udp_disconnect_socket_fd;
|
||||
|
||||
int radius_pid_select;
|
||||
|
||||
BYTE radius_access_id_select;
|
||||
BYTE radius_accounting_id_select;
|
||||
BYTE radius_disconnect_id_select;
|
||||
|
||||
RADIUS_MSG radius_msg_pdu;
|
||||
|
||||
RADIUS_PID radius_pid[RADIUS_MAX_NUM_OF_PID];
|
||||
|
||||
BYTE radius_udp_msg_recv_buf[RADIUS_MAX_LEN_OF_UDP_MSG];
|
||||
|
||||
WORD radius_mon_flag;
|
||||
|
||||
BYTE radius_asci_tmp_buf[RADIUS_MAX_ASCITMP_LEN];
|
||||
BYTE radius_asci_out_buf[RADIUS_MAX_ASCIIOUT_LEN];
|
||||
BYTE radius_asci_in_buf[RADIUS_MAX_ASCIIIN_LEN];
|
||||
|
||||
char radius_msg_type_str[RADIUS_MAX_LEN_OF_MSG_TYEP];
|
||||
|
||||
RADIUS_ATTR_PARSE_FUNCTION radius_attr_parse_function[RADIUS_MAX_NUM_OF_ATTRIBUTE];
|
||||
|
||||
RADIUS_SAP radius_sap[RADIUS_MAX_NUM_OF_SAP];
|
||||
|
||||
RADIUS_NAS_INFO radius_nas_info[RADIUS_MAX_NUM_OF_NAS];
|
||||
//==============================================================
|
||||
|
||||
int radius_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
radius_init_socket();
|
||||
|
||||
for (i = 0; i < RADIUS_MAX_NUM_OF_PID; i++)
|
||||
{
|
||||
radius_init_pid(i);
|
||||
}
|
||||
|
||||
radius_attr_parse_init();
|
||||
|
||||
memset(&radius_msg_pdu, 0, sizeof(RADIUS_MSG));
|
||||
|
||||
memset(&radius_nas_info, 0, sizeof(RADIUS_NAS_INFO) * RADIUS_MAX_NUM_OF_NAS);
|
||||
/*
|
||||
for (i = 0; i < RADIUS_MAX_NUM_OF_SAP; i++)
|
||||
{
|
||||
strcpy(radius_nas_share_key[i], "");
|
||||
strcpy(radius_nas_password[i], "");
|
||||
}*/
|
||||
|
||||
radius_pid_select = 0;
|
||||
|
||||
radius_access_id_select = 0;
|
||||
radius_accounting_id_select = 0;
|
||||
radius_disconnect_id_select = 0;
|
||||
|
||||
strcpy((char *)radius_asci_in_buf, "\0");
|
||||
strcpy((char *)radius_asci_out_buf, "\0");
|
||||
strcpy((char *)radius_asci_tmp_buf, "\0");
|
||||
strcpy((char *)radius_udp_msg_recv_buf, "\0");
|
||||
strcpy(radius_msg_type_str, "\0");
|
||||
radius_mon_flag = RADIUS_MONITOR_NONE;
|
||||
radius_debug_set();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void radius_t10ms(void)
|
||||
{
|
||||
static DWORD cnt_100ms = 0;
|
||||
|
||||
if (!(++cnt_100ms % 10))
|
||||
{
|
||||
radius_mon();
|
||||
cnt_100ms = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void radius_timer(void)
|
||||
{
|
||||
radius_recv_udp_msg();
|
||||
|
||||
radius_t10ms();
|
||||
|
||||
radius_fsm();
|
||||
}
|
||||
|
||||
int radius_bind(RADIUS_SAP *sap)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ((sap == NULL) || (sap->radius_ind == NULL) || (sap->radius_cnf == NULL))
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < RADIUS_MAX_NUM_OF_SAP; i++)
|
||||
{
|
||||
if ((radius_sap[i].radius_ind != NULL) || (radius_sap[i].radius_cnf != NULL))
|
||||
continue;
|
||||
|
||||
memcpy(&radius_sap[i], sap, sizeof(RADIUS_SAP));
|
||||
|
||||
radius_sap[i].name[RADIUS_MAX_LEN_OF_USER_NAME - 1] = '\0';
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
495
plat/radius/src/radius_debug.c
Normal file
495
plat/radius/src/radius_debug.c
Normal file
@@ -0,0 +1,495 @@
|
||||
#include "./include/radius_pub.h"
|
||||
#include "./include/radius_inc.h"
|
||||
|
||||
#define RADIUS_DEBUG_ID 31
|
||||
|
||||
static char ascii[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
|
||||
|
||||
static BYTE log_help[] = {
|
||||
"RADIUS Debug Monitor Help:\n\r\
|
||||
\n\r\
|
||||
1.[help] display help menu\n\r\
|
||||
2.[log all/none] display all/none logs\n\r\
|
||||
3.[log error on/off] display error logs\n\r\
|
||||
4.[log warn on/off] display warn logs\n\r\
|
||||
5.[log radius msg on/off] display radius msg logs\n\r\
|
||||
6.[list nas] display nas information\n\r\n\r"
|
||||
};
|
||||
|
||||
static WORD disp_page[10];
|
||||
static BYTE *disp_ptr = (BYTE *) disp_page;
|
||||
|
||||
static DWORD radius_debug_status_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,RADIUS_DEBUG_ID + 2,1
|
||||
};
|
||||
|
||||
static BYTE radius_debug_status = 1;
|
||||
|
||||
static DWORD radius_debug_name_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,RADIUS_DEBUG_ID + 2,2
|
||||
};
|
||||
|
||||
static DWORD radius_debug_ascin_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,RADIUS_DEBUG_ID + 2,3
|
||||
};
|
||||
|
||||
static DWORD radius_debug_ascout_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,RADIUS_DEBUG_ID + 2,4
|
||||
};
|
||||
|
||||
static DWORD radius_debug_page_title[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,RADIUS_DEBUG_ID + 2,1,1
|
||||
};
|
||||
|
||||
static DWORD radius_debug_page_line[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,RADIUS_DEBUG_ID + 2,1,2,1
|
||||
};
|
||||
|
||||
const static BYTE RADIUS_BASE_ID_LEN = 15;
|
||||
const static BYTE RADIUS_PAGE_POINT = 14;
|
||||
const static BYTE RADIUS_LINE_POINT = 15;
|
||||
|
||||
static BYTE radius_title1_p[] =
|
||||
{
|
||||
" RADIUS Page 02 \n\r\
|
||||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
|
||||
Subpage\n\r\
|
||||
RADIUS_PID\n\r"
|
||||
};
|
||||
|
||||
BYTE radius_disp_line(BYTE page, BYTE line)
|
||||
{
|
||||
BYTE disp_length;
|
||||
|
||||
disp_length = 16;
|
||||
disp_ptr = (BYTE *) disp_page;
|
||||
|
||||
switch (page)
|
||||
{
|
||||
case 1: // Page 1: pid Info
|
||||
if (line == 0)
|
||||
{
|
||||
disp_ptr = (BYTE *) &disp_page[page];
|
||||
disp_length = 2;
|
||||
}
|
||||
else
|
||||
disp_ptr = (BYTE *) radius_pid + disp_page[page] * sizeof(RADIUS_PID) + (line - 1) * 16;
|
||||
break;
|
||||
default:
|
||||
disp_length = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return disp_length;
|
||||
}
|
||||
|
||||
void radius_disp_page(BYTE page)
|
||||
{
|
||||
BYTE disp_line;
|
||||
BYTE disp_length;
|
||||
|
||||
radius_debug_page_line[RADIUS_PAGE_POINT] = page + 5;
|
||||
|
||||
for (disp_line = 0; disp_line < 20; disp_line++)
|
||||
{
|
||||
disp_length = radius_disp_line(page, disp_line);
|
||||
radius_debug_page_line[RADIUS_LINE_POINT] = disp_line + 2;
|
||||
radius_debug_page_line[RADIUS_LINE_POINT + 1] = 2; // Data Pointer
|
||||
debug_set_response(RADIUS_BASE_ID_LEN + 2, radius_debug_page_line, disp_ptr, disp_length);
|
||||
}
|
||||
}
|
||||
|
||||
int radius_debug_set(void)
|
||||
{
|
||||
BYTE page;
|
||||
BYTE data[10];
|
||||
BYTE *ptr;
|
||||
BYTE version[16];
|
||||
|
||||
bzero(disp_page, 20);
|
||||
|
||||
ptr = data;
|
||||
|
||||
sprintf((char*)version, "V%d.%d.%d%d", RADIUS_Version[0], RADIUS_Version[1], RADIUS_Version[2], RADIUS_Version[3]);
|
||||
debug_set_response(RADIUS_BASE_ID_LEN, radius_debug_status_id, (BYTE *)&radius_debug_status, 1);
|
||||
debug_set_response(RADIUS_BASE_ID_LEN, radius_debug_name_id, version, 10);
|
||||
debug_set_response(RADIUS_BASE_ID_LEN, radius_debug_ascin_id, radius_asci_in_buf, 4096);
|
||||
debug_set_response(RADIUS_BASE_ID_LEN, radius_debug_ascout_id, radius_asci_out_buf, 4096);
|
||||
|
||||
for (page = 1; page < 4; page++)
|
||||
{
|
||||
switch (page)
|
||||
{
|
||||
case 1: //page 1
|
||||
ptr = radius_title1_p;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
radius_debug_page_title[RADIUS_PAGE_POINT] = 5 + page;
|
||||
debug_set_response(RADIUS_BASE_ID_LEN + 1, radius_debug_page_title, ptr, strlen((char *)ptr));
|
||||
radius_disp_page(page);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int radius_asciout_proc(char *out_str)
|
||||
{
|
||||
int out_len;
|
||||
|
||||
out_len = strlen(out_str);
|
||||
|
||||
radius_asci_out_buf[RADIUS_MAX_ASCIIOUT_LEN - 1] = '\0';
|
||||
|
||||
if (out_len + strlen((char *)radius_asci_out_buf) > RADIUS_MAX_ASCIIOUT_LEN - 2)
|
||||
{
|
||||
strcpy((char *)radius_asci_out_buf, out_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat((char *)radius_asci_out_buf, out_str);
|
||||
}
|
||||
|
||||
radius_asci_out_buf[RADIUS_MAX_ASCIIOUT_LEN - 1] = '\0';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void radius_list_nas()
|
||||
{
|
||||
int i;
|
||||
BYTE tmp_buf[256] = "";
|
||||
BYTE out_buf[2048] = "";
|
||||
struct in_addr nas_addr;
|
||||
RADIUS_NAS_INFO *nas_info_ptr;
|
||||
|
||||
sprintf((char*)out_buf, "NAS id\tip address\t\tpassword\t\t\tshare key\r\n");
|
||||
|
||||
for (i = 0; i < RADIUS_MAX_NUM_OF_NAS; i++)
|
||||
{
|
||||
nas_info_ptr = radius_get_nas_info_ptr(i);
|
||||
|
||||
if (nas_info_ptr->flag != 1)
|
||||
continue;
|
||||
|
||||
nas_addr.s_addr = nas_info_ptr->nas_ip;
|
||||
|
||||
sprintf((char*)tmp_buf, "%d\t%s\t\t%s\t\t\t%s\r\n", i, inet_ntoa(nas_addr), nas_info_ptr->password, nas_info_ptr->share_key);
|
||||
strcat((char*)out_buf, (char*)tmp_buf);
|
||||
}
|
||||
|
||||
radius_asciout_proc((char*)out_buf);
|
||||
}
|
||||
|
||||
void radius_mon(void)
|
||||
{
|
||||
BYTE in_page, err_fg = 0;
|
||||
BYTE *ascii_in_ptr = NULL;
|
||||
BYTE *str_start = NULL;
|
||||
WORD str_len;
|
||||
WORD num;
|
||||
|
||||
if ((str_len = strlen((char *)radius_asci_in_buf)) > 0)
|
||||
{
|
||||
in_page = radius_asci_in_buf[0] - 1;
|
||||
ascii_in_ptr = radius_asci_in_buf + 1;
|
||||
|
||||
if (in_page > 3)
|
||||
err_fg = 1;
|
||||
else if (strcmp((char *)ascii_in_ptr,"log error on") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag | RADIUS_MONITOR_ERROR;
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log error off") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_ERROR);
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log warn on") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag | RADIUS_MONITOR_WARN;
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log warn off") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_WARN);
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log radius msg on") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag | RADIUS_MONITOR_SDRV_MSG;
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_ACCESS_MSG);
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_ACCT_MSG);
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_DISC_MSG);
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log radius msg off") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_SDRV_MSG);
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log access msg on") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag | RADIUS_MONITOR_ACCESS_MSG;
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log access msg off") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_ACCESS_MSG);
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log acct msg on") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag | RADIUS_MONITOR_ACCT_MSG;
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log acct msg off") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_ACCT_MSG);
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log disc msg on") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag | RADIUS_MONITOR_DISC_MSG;
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log disc msg off") == 0)
|
||||
{
|
||||
radius_mon_flag = radius_mon_flag & (~RADIUS_MONITOR_DISC_MSG);
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log all") == 0)
|
||||
{
|
||||
radius_mon_flag = RADIUS_MONITOR_ALL;
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"log none") == 0)
|
||||
{
|
||||
radius_mon_flag = RADIUS_MONITOR_NONE;
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr, "list nas") == 0)
|
||||
{
|
||||
radius_list_nas();
|
||||
}
|
||||
else if (strcmp((char *)ascii_in_ptr,"help") == 0)
|
||||
{
|
||||
radius_asciout_proc((char*)log_help);
|
||||
}
|
||||
else if (isdigit(ascii_in_ptr[0]))
|
||||
{
|
||||
num = strtoul((char *)ascii_in_ptr, NULL, 10);
|
||||
disp_page[in_page] = num;
|
||||
radius_disp_page(in_page);
|
||||
}
|
||||
else if ((str_start = (BYTE *)strstr((char *)ascii_in_ptr, ">")) != NULL)
|
||||
{
|
||||
num = strtoul((char *)(str_start + 1), NULL, 10);
|
||||
disp_page[in_page] += num;
|
||||
radius_disp_page(in_page);
|
||||
}
|
||||
else if ((str_start = (BYTE *)strstr((char *)ascii_in_ptr, "<"))!= NULL)
|
||||
{
|
||||
num = strtoul((char *)(str_start + 1), NULL, 10);
|
||||
disp_page[in_page] -= num;
|
||||
radius_disp_page(in_page);
|
||||
}
|
||||
else
|
||||
err_fg = 1;
|
||||
|
||||
if (err_fg == 0)
|
||||
radius_asciout_proc("Command OK!\n\r");
|
||||
else
|
||||
radius_asciout_proc("Command Error!\n\r");
|
||||
|
||||
strcpy((char *)radius_asci_in_buf, "\0");
|
||||
}
|
||||
}
|
||||
|
||||
int radius_hex_to_ascii(BYTE *from_hex, BYTE from_len, BYTE *to_asc)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
j = 0;
|
||||
|
||||
for (i = 0; i< from_len; i++)
|
||||
{
|
||||
to_asc[j] = ascii[from_hex[i] >> 4];
|
||||
j++;
|
||||
to_asc[j] = ascii[from_hex[i] & 0x0F];
|
||||
j++;
|
||||
to_asc[j] = ' ';
|
||||
j++;
|
||||
}
|
||||
|
||||
to_asc[j] = '\0';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int radius_log_err(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char err_msg[2048];
|
||||
char time_str[1024];
|
||||
struct tm *t;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
if ((radius_mon_flag & RADIUS_MONITOR_ERROR) == RADIUS_MONITOR_ERROR)
|
||||
{
|
||||
gettimeofday(&tv, &tz);
|
||||
t = localtime(&tv.tv_sec);
|
||||
sprintf(time_str, "[%d:%d:%d.%ld]:", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(err_msg, fmt, ap);
|
||||
|
||||
if (strlen((char *)err_msg) >= RADIUS_MAX_ASCITMP_LEN)
|
||||
sprintf((char *)radius_asci_tmp_buf, "\33[31m%slog msg is too long: %zu\r\n", time_str, strlen((char *)err_msg));
|
||||
else
|
||||
sprintf((char *)radius_asci_tmp_buf, "\33[31m%s%s\r\n", time_str, err_msg);
|
||||
|
||||
strcat((char *)radius_asci_tmp_buf, "\33[37m");
|
||||
|
||||
radius_asciout_proc((char*)radius_asci_tmp_buf);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int radius_log_event(const char *fmt, ...)
|
||||
{
|
||||
char time_str[1024];
|
||||
char msg[2048];
|
||||
va_list ap;
|
||||
struct tm *t;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
if ((radius_mon_flag & RADIUS_MONITOR_EVENT) == RADIUS_MONITOR_EVENT)
|
||||
{
|
||||
gettimeofday(&tv, &tz);
|
||||
t = localtime(&tv.tv_sec);
|
||||
sprintf(time_str, "[%d:%d:%d.%ld]:", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(msg, fmt, ap);
|
||||
|
||||
radius_asciout_proc("\33[34m");
|
||||
|
||||
if ((strlen((char *)msg) + strlen(time_str)) >= RADIUS_MAX_ASCITMP_LEN)
|
||||
sprintf((char *)radius_asci_tmp_buf, "%s log msg is too long: %zu\n\r", time_str, (strlen((char *)msg) + strlen(time_str)));
|
||||
else
|
||||
sprintf((char *)radius_asci_tmp_buf, "%s%s\n\r", time_str, msg);
|
||||
|
||||
strcat((char *)radius_asci_tmp_buf, "\33[37m");
|
||||
radius_asciout_proc((char *)radius_asci_tmp_buf);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_log_warn(const char *fmt, ...)
|
||||
{
|
||||
|
||||
char timestr[1024];
|
||||
char msg[2048];
|
||||
va_list ap;
|
||||
struct tm *t;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
if ((radius_mon_flag & RADIUS_MONITOR_WARN) == RADIUS_MONITOR_WARN)
|
||||
{
|
||||
gettimeofday(&tv, &tz);
|
||||
t = localtime(&tv.tv_sec);
|
||||
sprintf(timestr, "[%d:%d:%d.%ld]:", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(msg, fmt, ap);
|
||||
|
||||
radius_asciout_proc("\33[33m");
|
||||
|
||||
if ((strlen((char *)msg) + strlen(timestr)) >= RADIUS_MAX_ASCITMP_LEN)
|
||||
sprintf((char *)radius_asci_tmp_buf, "%s log msg is too long: %zu\n\r", timestr, (strlen((char *)msg) + strlen(timestr)));
|
||||
else
|
||||
sprintf((char *)radius_asci_tmp_buf, "%s%s\n\r", timestr, msg);
|
||||
|
||||
strcat((char *)radius_asci_tmp_buf, "\33[37m");
|
||||
radius_asciout_proc((char *)radius_asci_tmp_buf);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_log_send_recv_msg(BYTE *msg, int len, RADIUS_ADDR *addr, BYTE msg_type, BYTE flag)
|
||||
{
|
||||
struct tm *t;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
char str[RADIUS_MAX_LEN_OF_MSG] = "";
|
||||
char time_str[1024];
|
||||
struct sockaddr_in src_addr;
|
||||
BYTE log_flag = 0;
|
||||
|
||||
switch (msg_type)
|
||||
{
|
||||
case RADIUS_MSG_TYPE_ACCESS_ACCEPT:
|
||||
case RADIUS_MSG_TYPE_ACCESS_REQUEST:
|
||||
case RADIUS_MSG_TYPE_ACCESS_REJECT:
|
||||
case RADIUS_MSG_TYPE_ACCESS_CHALLENGE:
|
||||
if ((radius_mon_flag & RADIUS_MONITOR_ACCESS_MSG) == RADIUS_MONITOR_ACCESS_MSG)
|
||||
log_flag = 1;
|
||||
break;
|
||||
case RADIUS_MSG_TYPE_ACCOUNTING_REQUEST:
|
||||
case RADIUS_MSG_TYPE_ACCOUNTING_RESPONSE:
|
||||
if ((radius_mon_flag & RADIUS_MONITOR_ACCT_MSG) == RADIUS_MONITOR_ACCT_MSG)
|
||||
log_flag = 1;
|
||||
break;
|
||||
case RADIUS_MSG_TYPE_DISCONNECT_REQUEST:
|
||||
case RADIUS_MSG_TYPE_DISCONNECT_ACK:
|
||||
case RADIUS_MSG_TYPE_DISCONNECT_NAK:
|
||||
if ((radius_mon_flag & RADIUS_MONITOR_DISC_MSG) == RADIUS_MONITOR_DISC_MSG)
|
||||
log_flag = 1;
|
||||
break;
|
||||
default:
|
||||
if ((radius_mon_flag & RADIUS_MONITOR_SDRV_MSG) == RADIUS_MONITOR_SDRV_MSG)
|
||||
log_flag = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (log_flag == 1)
|
||||
{
|
||||
gettimeofday(&tv, &tz);
|
||||
t = localtime(&tv.tv_sec);
|
||||
sprintf(time_str, "[%d:%d:%d.%ld]:", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
|
||||
|
||||
radius_msg_to_fmt(msg, len, str, RADIUS_MAX_LEN_OF_MSG);
|
||||
|
||||
radius_asciout_proc("\33[34m");
|
||||
|
||||
if ((strlen(str) + strlen(time_str) + 64) >= RADIUS_MAX_ASCITMP_LEN)
|
||||
sprintf((char *)radius_asci_tmp_buf, "%s log msg is too long: %zu\n\r", time_str, (strlen(str) + strlen(time_str)));
|
||||
else
|
||||
{
|
||||
src_addr.sin_addr.s_addr = addr->addr.ipV4;
|
||||
if (flag == RADIUS_RECV_MSG_FLAG)
|
||||
{
|
||||
sprintf((char *)radius_asci_tmp_buf, "%sRecieve Msg<===src port: %d, src ip: %s\r\n%s\n\r", time_str, addr->port, inet_ntoa(src_addr.sin_addr), str);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf((char *)radius_asci_tmp_buf, "%sSend Msg===>dest port: %d, dest ip: %s\r\n%s\n\r", time_str, addr->port, inet_ntoa(src_addr.sin_addr), str);
|
||||
}
|
||||
}
|
||||
|
||||
strcat((char *)radius_asci_tmp_buf, "\33[37m");
|
||||
radius_asciout_proc((char *)radius_asci_tmp_buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
340
plat/radius/src/radius_fsm.c
Normal file
340
plat/radius/src/radius_fsm.c
Normal file
@@ -0,0 +1,340 @@
|
||||
#include "./include/radius_pub.h"
|
||||
|
||||
#define test_nowsms_enable 0
|
||||
#define test_css_enable 0
|
||||
|
||||
#define radius_set_pid_state(val) do { \
|
||||
pid_ptr->state = val; \
|
||||
radius_log_event("[%05d] \33[32m%s\33[0m transfer to state \33[36m%s\33[0m\r\n", pid, __FUNCTION__, #val); \
|
||||
} while(0)
|
||||
|
||||
#define radius_set_pid_timer(val) do { \
|
||||
pid_ptr->timer = val; \
|
||||
} while(0)
|
||||
|
||||
#if(test_nowsms_enable)
|
||||
static void radius_test(int pid, BYTE sap_index, WORD *usr_pid, RADIUS_MSG *ptr_radius)
|
||||
{
|
||||
RADIUS_MSG pdu;
|
||||
|
||||
if(usr_pid == NULL || ptr_radius == NULL)
|
||||
return;
|
||||
memset(&pdu, 0, sizeof(RADIUS_MSG));
|
||||
pdu.msg_type = RADIUS_MSG_TYPE_ACCESS_ACCEPT;
|
||||
pdu.msg.access_accept.message_authenticator.flag = 1;
|
||||
radius_send_access_accept(sap_index, pid, *usr_pid, &pdu);
|
||||
return;
|
||||
}
|
||||
#elif(test_css_enable)
|
||||
static void radius_test(int pid, BYTE sap_index, WORD *usr_pid, RADIUS_MSG *ptr_radius)
|
||||
{
|
||||
static BYTE user_id = 0;
|
||||
BYTE count = 0;
|
||||
int num, i;
|
||||
RADIUS_MSG pdu;
|
||||
RADIUS_ACCESS_ACCEPT *access_accept;
|
||||
RADIUS_VENDOR_SPECIFIC *vendor_specific;
|
||||
RADIUS_VENDOR_ATTRIBUTE_3GPP2_PPAC *ppac;
|
||||
RADIUS_VENDOR_ATTRIBUTE_3GPP2_PPAQ *ppaq;
|
||||
|
||||
if(usr_pid == NULL || ptr_radius == NULL)
|
||||
return;
|
||||
if(ptr_radius->msg.access_request.user_password.flag == 1)
|
||||
{
|
||||
count = 1;
|
||||
*usr_pid = user_id;
|
||||
user_id++;
|
||||
}
|
||||
else if((num = ptr_radius->msg.access_request.vendor_specific.num) > 0)
|
||||
{
|
||||
for(i = 0; i < num; i++)
|
||||
{
|
||||
vendor_specific = &ptr_radius->msg.access_request.vendor_specific;
|
||||
ppaq = &vendor_specific->vendor_specific[i].attribute_3gpp2.ppaq;
|
||||
if((vendor_specific->vendor_specific[i].vendor_type == RADIUS_VENDOR_TYPE_3GPP2_PPAQ) && (ppaq->qid.flag == 1))
|
||||
{
|
||||
*usr_pid = (ppaq->qid.qid.value >> 16) & 0xFF;
|
||||
count = (ppaq->qid.qid.value & 0xFF) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memset(&pdu, 0, sizeof(RADIUS_MSG));
|
||||
pdu.msg_type = RADIUS_MSG_TYPE_ACCESS_ACCEPT;
|
||||
access_accept = &pdu.msg.access_accept;
|
||||
vendor_specific = &access_accept->vendor_specific;
|
||||
num = vendor_specific->num;
|
||||
vendor_specific->vendor_specific[num].flag = 1;
|
||||
vendor_specific->vendor_specific[num].vendor_type = RADIUS_VENDOR_TYPE_3GPP2_PPAC;
|
||||
ppac = &vendor_specific->vendor_specific[num].attribute_3gpp2.ppac;
|
||||
ppac->sfs.flag = 1;
|
||||
//ppac->sfs.sfs = 2; //dt && dq
|
||||
ppac->sfs.sfs = 1; //vt && vq
|
||||
vendor_specific->num++;
|
||||
num = vendor_specific->num;
|
||||
vendor_specific->vendor_specific[num].vendor_type = RADIUS_VENDOR_TYPE_3GPP2_PPAQ;
|
||||
ppaq = &vendor_specific->vendor_specific[num].attribute_3gpp2.ppaq;
|
||||
ppaq->qid.flag = 1;
|
||||
ppaq->qid.qid.value = ((*usr_pid) << 16) | (count * 1);
|
||||
|
||||
if(ppac->sfs.sfs == 1)
|
||||
{
|
||||
ppaq->vq.flag = 1;
|
||||
ppaq->vq.vq.integer = (count + 1) * 1024 * 20;
|
||||
ppaq->vq.vq.exponent = 1;
|
||||
ppaq->vt.flag = 1;
|
||||
ppaq->vt.vt.integer = (count + 1) * 1024 * 20 - 1024 * 2;
|
||||
ppaq->vt.vt.exponent = 1;
|
||||
}
|
||||
else if(ppac->sfs.sfs == 2)
|
||||
{
|
||||
ppaq->dq.flag = 1;
|
||||
ppaq->dq.dq.value = count * 20;
|
||||
ppaq->dt.flag = 1;
|
||||
ppaq->dt.dt.value = count * 20 - 2;
|
||||
}
|
||||
|
||||
vendor_specific->num++;
|
||||
access_accept->message_authenticator.flag = 1;
|
||||
radius_send_access_accept(sap_index, pid, *usr_pid, &pdu);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
int radius_pid_indication_process(int pid)
|
||||
{
|
||||
BYTE sap_index;
|
||||
RADIUS_PID *pid_ptr;
|
||||
|
||||
pid_ptr = radius_get_pid_ptr(pid);
|
||||
|
||||
sap_index = pid_ptr->sap_index;
|
||||
|
||||
switch (pid_ptr->state)
|
||||
{
|
||||
case RADIUS_PID_IND_STATE_IDLE:
|
||||
if (pid_ptr->rv_msg_flag != 0)
|
||||
{
|
||||
pid_ptr->rv_msg_flag = 0;
|
||||
|
||||
if (radius_sap[sap_index].radius_ind == NULL)
|
||||
return 1;
|
||||
#if(test_nowsms_enable || test_css_enable)
|
||||
{
|
||||
radius_test(pid, sap_index, &pid_ptr->usr_pid, &radius_msg_pdu);
|
||||
}
|
||||
#else
|
||||
if (radius_sap[sap_index].radius_ind(&pid_ptr->usr_pid, pid, &radius_msg_pdu) < 0)
|
||||
{
|
||||
radius_log_err("[%04d] %s: radius_ind error! usr_pid=%d\r\n", pid, __FUNCTION__, pid_ptr->usr_pid);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
radius_log_event("[%04d] %s: recv indication and send it to up layer\r\n", pid, __FUNCTION__);
|
||||
|
||||
radius_set_pid_state(RADIUS_PID_IND_STATE_WAIT_FOR_USER_RESP);
|
||||
radius_set_pid_timer(RADIUS_TIMER_16S);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case RADIUS_PID_IND_STATE_WAIT_FOR_USER_RESP:
|
||||
if (pid_ptr->sd_msg_flag == 1)
|
||||
{
|
||||
pid_ptr->sd_msg_flag = 0;
|
||||
|
||||
radius_send_msg(pid);
|
||||
|
||||
radius_set_pid_timer(RADIUS_TIMER_16S);
|
||||
|
||||
radius_set_pid_state(RADIUS_PID_IND_STATE_WAIT_FOR_TERMINATE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (pid_ptr->timer > 0)
|
||||
{
|
||||
if (--pid_ptr->timer == 0)
|
||||
{
|
||||
radius_log_warn("[%04d] %s: wait user response time out\r\n", pid, __FUNCTION__);
|
||||
radius_set_pid_state(RADIUS_PID_IND_STATE_TERMINATE);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RADIUS_PID_IND_STATE_WAIT_FOR_TERMINATE:
|
||||
if (pid_ptr->rv_msg_flag != 0)
|
||||
{
|
||||
radius_send_msg(pid);
|
||||
|
||||
pid_ptr->rv_msg_flag = 0;
|
||||
}
|
||||
|
||||
if (pid_ptr->timer > 0)
|
||||
{
|
||||
if (--pid_ptr->timer == 0)
|
||||
{
|
||||
radius_set_pid_state(RADIUS_PID_IND_STATE_TERMINATE);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_pid_indication_fsm(int pid)
|
||||
{
|
||||
switch (radius_pid_indication_process(pid))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
radius_init_pid(pid);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_pid_request_process(int pid)
|
||||
{
|
||||
BYTE sap_index;
|
||||
RADIUS_PID *pid_ptr;
|
||||
|
||||
pid_ptr = radius_get_pid_ptr(pid);
|
||||
sap_index = pid_ptr->sap_index;
|
||||
|
||||
switch (pid_ptr->state)
|
||||
{
|
||||
case RADIUS_PID_REQ_STATE_IDLE:
|
||||
if (pid_ptr->sd_msg_flag == 1)
|
||||
{
|
||||
pid_ptr->sd_msg_flag = 0;
|
||||
|
||||
radius_send_msg(pid);
|
||||
|
||||
radius_set_pid_state(RADIUS_PID_REQ_STATE_WAIT_FOR_PEER_RESP);
|
||||
|
||||
radius_set_pid_timer(RADIUS_TIMER_16S);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (pid_ptr->timer > 0)
|
||||
{
|
||||
if (--pid_ptr->timer == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
break;
|
||||
case RADIUS_PID_REQ_STATE_WAIT_FOR_PEER_RESP:
|
||||
if (pid_ptr->rv_msg_flag != 0)
|
||||
{
|
||||
radius_log_event("[%04d]%s: recv peer response and send it to up layer\r\n", pid, __FUNCTION__);
|
||||
|
||||
radius_set_pid_state(RADIUS_PID_REQ_STATE_TERMINATE);
|
||||
|
||||
if (radius_sap[sap_index].radius_cnf == NULL)
|
||||
{
|
||||
radius_log_err("[%04d] %s: radius_cnf error! usr_pid=%d\r\n", pid, __FUNCTION__, pid_ptr->usr_pid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
radius_sap[sap_index].radius_cnf(pid_ptr->usr_pid, pid, &radius_msg_pdu);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (pid_ptr->timer > 0)
|
||||
{
|
||||
if (--pid_ptr->timer == 0)
|
||||
{
|
||||
radius_log_warn("[%04d] %s: wait peer response time out\r\n", pid, __FUNCTION__);
|
||||
radius_set_pid_state(RADIUS_PID_REQ_STATE_TERMINATE);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pid_ptr->timer % RADIUS_RETRANS_TIMER) == 0)
|
||||
{
|
||||
radius_send_msg(pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_pid_request_fsm(int pid)
|
||||
{
|
||||
switch (radius_pid_request_process(pid))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
radius_init_pid(pid);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_p_fsm(int pid)
|
||||
{
|
||||
RADIUS_PID *pid_ptr;
|
||||
|
||||
if ((pid_ptr = radius_get_pid_ptr(pid)) == NULL)
|
||||
return -1;
|
||||
|
||||
switch (pid_ptr->type)
|
||||
{
|
||||
case RADIUS_PID_TYPE_IND:
|
||||
radius_pid_indication_fsm(pid);
|
||||
break;
|
||||
case RADIUS_PID_TYPE_REQ:
|
||||
radius_pid_request_fsm(pid);
|
||||
break;
|
||||
default:
|
||||
radius_init_pid(pid);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_fsm(void)
|
||||
{
|
||||
int i;
|
||||
RADIUS_PID *pid_ptr;
|
||||
|
||||
for (i = 0; i < RADIUS_MAX_NUM_OF_PID; i++)
|
||||
{
|
||||
pid_ptr = radius_get_pid_ptr(i);
|
||||
|
||||
if (pid_ptr->flag != 1)
|
||||
continue;
|
||||
|
||||
radius_p_fsm(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
9794
plat/radius/src/radius_function.c
Normal file
9794
plat/radius/src/radius_function.c
Normal file
File diff suppressed because it is too large
Load Diff
277
plat/radius/src/radius_if.c
Normal file
277
plat/radius/src/radius_if.c
Normal file
@@ -0,0 +1,277 @@
|
||||
#include "./include/radius_pub.h"
|
||||
|
||||
int radius_set_nas_info(BYTE sap_index, BYTE id, RADIUS_NAS_INFORMATION *nas_information)
|
||||
{
|
||||
RADIUS_NAS_INFO *nas_info_ptr;
|
||||
|
||||
if ((sap_index >= RADIUS_MAX_NUM_OF_SAP) || ((nas_info_ptr = radius_get_nas_info_ptr(id)) == NULL))
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d, nas id=%d\r\n", __FUNCTION__, sap_index, id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
nas_info_ptr->flag = 1;
|
||||
|
||||
nas_info_ptr->sap_index = sap_index;
|
||||
|
||||
nas_info_ptr->nas_ip = nas_information->nas_ip;
|
||||
strcpy((char*)nas_info_ptr->share_key, (char*)nas_information->share_key);
|
||||
strcpy((char*)nas_info_ptr->password, (char*)nas_information->password);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_delet_nas_info(BYTE sap_index, BYTE id)
|
||||
{
|
||||
RADIUS_NAS_INFO *nas_info_pt;
|
||||
|
||||
if (((nas_info_pt = radius_get_nas_info_ptr(id)) == NULL) || (nas_info_pt->flag != 1) || (nas_info_pt->sap_index != sap_index))
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d, nas id=%d\r\n", __FUNCTION__, sap_index, id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(nas_info_pt, 0, sizeof(RADIUS_NAS_INFO));
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
int radius_set_local_nas(BYTE sap_index, char *nas_password, char *nas_share_key)
|
||||
{
|
||||
if (sap_index >= RADIUS_MAX_NUM_OF_SAP)
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d\r\n", __FUNCTION__, sap_index);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(radius_nas_password[sap_index], nas_password);
|
||||
strcpy(radius_nas_share_key[sap_index], nas_share_key);
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
int radius_send_access_request(BYTE sap_index, WORD usr_pid, RADIUS_MSG *msg_pdu, RADIUS_ADDR *addr)
|
||||
{
|
||||
int pid;
|
||||
BYTE identifier;
|
||||
BYTE authenticator[RADIUS_MAX_LEN_OF_AUTH];
|
||||
int msg_len, nas_id;
|
||||
BYTE msg[RADIUS_MAX_LEN_OF_MSG] = "";
|
||||
RADIUS_PID *pid_ptr;
|
||||
struct in_addr ip_addr;
|
||||
// int server_id;
|
||||
// struct in_addr ip_addr;
|
||||
|
||||
if ((sap_index >= RADIUS_MAX_NUM_OF_SAP) || (msg_pdu == NULL) || (addr == NULL))
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d, msg_pdu=0x%X, addr=ox%X\r\n", __FUNCTION__, sap_index, msg_pdu, addr);
|
||||
return -1;
|
||||
}
|
||||
radius_log_event("%s: enter! usr_pid=%d\r\n", __FUNCTION__, usr_pid);
|
||||
|
||||
/* if ((server_id = radius_accord_ip_search_server_info(addr->addr.ipV4)) < 0)
|
||||
{
|
||||
ip_addr.s_addr = addr->addr.ipV4;
|
||||
radius_log_err("%s: server ip=%s, no such nas\r\n", __FUNCTION__, inet_ntoa(ip_addr));
|
||||
return -1;
|
||||
}*/
|
||||
if ((nas_id = radius_accord_ip_search_nas_info(addr->addr.ipV4)) < 0)
|
||||
{
|
||||
ip_addr.s_addr = addr->addr.ipV4;
|
||||
radius_log_warn("%s: nas ip = %s, no such nas ip\r\n", __FUNCTION__, inet_ntoa(ip_addr));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((msg_len = radius_encode_access_request(sap_index, &identifier, authenticator, msg, &msg_pdu->msg.access_request, nas_id)) < 0)
|
||||
{
|
||||
radius_log_err("%s: encode access request fail\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((pid = radius_get_pid()) < 0)
|
||||
{
|
||||
radius_log_err("%s: get pid fail\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid_ptr = radius_get_pid_ptr(pid);
|
||||
|
||||
pid_ptr->type = RADIUS_PID_TYPE_REQ;
|
||||
|
||||
pid_ptr->identifier = identifier;
|
||||
memcpy(pid_ptr->authenticator, authenticator, RADIUS_MAX_LEN_OF_AUTH);
|
||||
|
||||
pid_ptr->sd_msg_flag = 1;
|
||||
pid_ptr->sd_msg_type = RADIUS_MSG_TYPE_ACCESS_REQUEST;
|
||||
|
||||
memcpy(&pid_ptr->peer_addr, addr, sizeof(RADIUS_ADDR));
|
||||
pid_ptr->peer_addr.port = RADIUS_ACCESS_PORT;
|
||||
|
||||
memcpy(pid_ptr->msg, msg, msg_len);
|
||||
pid_ptr->msg_len = msg_len;
|
||||
|
||||
pid_ptr->timer = RADIUS_TIMER_16S;
|
||||
|
||||
pid_ptr->sap_index = sap_index;
|
||||
pid_ptr->usr_pid = usr_pid;
|
||||
|
||||
radius_log_event("%s: success! usr_pid=%d, pid=%d\r\n", __FUNCTION__, usr_pid, pid);
|
||||
// radius_p_fsm(pid);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
int radius_send_access_accept(BYTE sap_index, WORD pid, WORD usr_pid, RADIUS_MSG *msg_pdu)
|
||||
{
|
||||
int msg_len;
|
||||
BYTE msg[RADIUS_MAX_LEN_OF_MSG] = "";
|
||||
RADIUS_PID *pid_ptr;
|
||||
|
||||
if ((sap_index >= RADIUS_MAX_NUM_OF_SAP) || (msg_pdu == NULL)
|
||||
|| ((pid_ptr = radius_get_pid_ptr(pid)) == NULL) || (pid_ptr->sap_index != sap_index)
|
||||
|| (pid_ptr->usr_pid != usr_pid)
|
||||
|| (pid_ptr->trans_req_msg_type != RADIUS_MSG_TYPE_ACCESS_REQUEST))
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d, msg_pdu=0x%X, pid=%d, usr_pid=%d\r\n", __FUNCTION__, sap_index, msg_pdu, pid, usr_pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((msg_len = radius_encode_access_accept(pid_ptr->identifier, pid_ptr->authenticator, msg, &msg_pdu->msg.access_accept, pid_ptr->nas_id)) < 0)
|
||||
{
|
||||
radius_log_err("%s: encode access accept fail\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid_ptr->sd_msg_flag = 1;
|
||||
pid_ptr->sd_msg_type = RADIUS_MSG_TYPE_ACCESS_ACCEPT;
|
||||
|
||||
memcpy(pid_ptr->msg, msg, msg_len);
|
||||
pid_ptr->msg_len = msg_len;
|
||||
radius_log_event("%s: success! usr_pid=%d, pid=%d\r\n", __FUNCTION__, usr_pid, pid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_send_access_reject(BYTE sap_index, WORD pid, WORD usr_pid, RADIUS_MSG *msg_pdu)
|
||||
{
|
||||
int msg_len;
|
||||
BYTE msg[RADIUS_MAX_LEN_OF_MSG] = "";
|
||||
RADIUS_PID *pid_ptr;
|
||||
|
||||
if ((sap_index >= RADIUS_MAX_NUM_OF_SAP) || (msg_pdu == NULL)
|
||||
|| ((pid_ptr = radius_get_pid_ptr(pid)) == NULL) || (pid_ptr->sap_index != sap_index)
|
||||
|| (pid_ptr->usr_pid != usr_pid)
|
||||
|| (pid_ptr->trans_req_msg_type != RADIUS_MSG_TYPE_ACCESS_REQUEST))
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d, msg_pdu=0x%X, pid=%d, usr_pid=%d\r\n", __FUNCTION__, sap_index, msg_pdu, pid, usr_pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((msg_len = radius_encode_access_reject(pid_ptr->identifier, pid_ptr->authenticator, msg, &msg_pdu->msg.access_reject, pid_ptr->nas_id)) < 0)
|
||||
{
|
||||
radius_log_err("%s: encode access reject fail\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid_ptr->sd_msg_flag = 1;
|
||||
pid_ptr->sd_msg_type = RADIUS_MSG_TYPE_ACCESS_REJECT;
|
||||
|
||||
memcpy(pid_ptr->msg, msg, msg_len);
|
||||
pid_ptr->msg_len = msg_len;
|
||||
radius_log_event("%s: success! usr_pid=%d, pid=%d\r\n", __FUNCTION__, usr_pid, pid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_send_accounting_response(BYTE sap_index, WORD pid, WORD usr_pid, RADIUS_MSG *msg_pdu)
|
||||
{
|
||||
int msg_len;
|
||||
BYTE msg[RADIUS_MAX_LEN_OF_MSG] = "";
|
||||
RADIUS_PID *pid_ptr;
|
||||
|
||||
if ((sap_index >= RADIUS_MAX_NUM_OF_SAP) || (msg_pdu == NULL)
|
||||
|| ((pid_ptr = radius_get_pid_ptr(pid)) == NULL) || (pid_ptr->sap_index != sap_index) || (pid_ptr->usr_pid != usr_pid) || (pid_ptr->trans_req_msg_type != RADIUS_MSG_TYPE_ACCOUNTING_REQUEST))
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d, msg_pdu=0x%X, pid=%d, usr_pid=%d\r\n", __FUNCTION__, sap_index, msg_pdu, pid, usr_pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((msg_len = radius_encode_accounting_response(pid_ptr->identifier, pid_ptr->authenticator, msg, &msg_pdu->msg.accounting_response, pid_ptr->nas_id)) < 0)
|
||||
{
|
||||
radius_log_err("%s: encode accounting response fail\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid_ptr->sd_msg_flag = 1;
|
||||
pid_ptr->sd_msg_type = RADIUS_MSG_TYPE_ACCOUNTING_RESPONSE;
|
||||
|
||||
memcpy(pid_ptr->msg, msg, msg_len);
|
||||
pid_ptr->msg_len = msg_len;
|
||||
radius_log_event("%s: success! usr_pid=%d, pid=%d\r\n", __FUNCTION__, usr_pid, pid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_send_disconnect_request(BYTE sap_index, WORD usr_pid, RADIUS_MSG *msg_pdu, RADIUS_ADDR *addr)
|
||||
{
|
||||
int pid;
|
||||
BYTE identifier;
|
||||
BYTE authenticator[RADIUS_MAX_LEN_OF_AUTH];
|
||||
int msg_len;
|
||||
BYTE msg[RADIUS_MAX_LEN_OF_MSG] = "";
|
||||
RADIUS_PID *pid_ptr;
|
||||
int nas_id;
|
||||
struct in_addr ip_addr;
|
||||
|
||||
if ((sap_index >= RADIUS_MAX_NUM_OF_SAP) || (msg_pdu == NULL) || (addr == NULL))
|
||||
{
|
||||
radius_log_err("%s: sap_index=%d, msg_pdu=0x%X, addr=ox%X\r\n", __FUNCTION__, sap_index, msg_pdu, addr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((nas_id = radius_accord_ip_search_nas_info(addr->addr.ipV4)) < 0)
|
||||
{
|
||||
ip_addr.s_addr = addr->addr.ipV4;
|
||||
radius_log_err("%s: nas ip=%s, no such nas\r\n", __FUNCTION__, inet_ntoa(ip_addr));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((msg_len = radius_encode_disconnect_request(&identifier, authenticator, msg, &msg_pdu->msg.disconnect_request, nas_id)) < 0)
|
||||
{
|
||||
radius_log_err("%s: encode disconnect request fail\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((pid = radius_get_pid()) < 0)
|
||||
{
|
||||
radius_log_err("%s: get pid fail\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid_ptr = radius_get_pid_ptr(pid);
|
||||
|
||||
pid_ptr->type = RADIUS_PID_TYPE_REQ;
|
||||
|
||||
pid_ptr->identifier = identifier;
|
||||
memcpy(pid_ptr->authenticator, authenticator, RADIUS_MAX_LEN_OF_AUTH);
|
||||
|
||||
pid_ptr->sd_msg_flag = 1;
|
||||
pid_ptr->sd_msg_type = RADIUS_MSG_TYPE_DISCONNECT_REQUEST;
|
||||
|
||||
memcpy(&pid_ptr->peer_addr, addr, sizeof(RADIUS_ADDR));
|
||||
pid_ptr->peer_addr.port = RADIUS_DISCONNECT_PORT;
|
||||
|
||||
memcpy(pid_ptr->msg, msg, msg_len);
|
||||
pid_ptr->msg_len = msg_len;
|
||||
|
||||
pid_ptr->timer = RADIUS_TIMER_16S;
|
||||
|
||||
pid_ptr->sap_index = sap_index;
|
||||
pid_ptr->nas_id = nas_id;
|
||||
radius_log_event("%s: success! usr_pid=%d, pid=%d\r\n", __FUNCTION__, usr_pid, pid);
|
||||
|
||||
// radius_p_fsm(pid);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
848
plat/radius/src/radius_md5.c
Normal file
848
plat/radius/src/radius_md5.c
Normal file
@@ -0,0 +1,848 @@
|
||||
/***********************************************************************/
|
||||
/** md5.c -- the source code for MD5 routines **/
|
||||
/** RSA Data Security, Inc. MD5 Message-Digest Algorithm **/
|
||||
/** Created: 2/17/90 RLR **/
|
||||
/** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **/
|
||||
/** 1992.2.13 Jouko Holopainen, 80x86 version **/
|
||||
/***********************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
/** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **/
|
||||
/** **/
|
||||
/** License to copy and use this software is granted provided that **/
|
||||
/** it is identified as the "RSA Data Security, Inc. MD5 Message- **/
|
||||
/** Digest Algorithm" in all material mentioning or referencing this **/
|
||||
/** software or this function. **/
|
||||
/** **/
|
||||
/** License is also granted to make and use derivative works **/
|
||||
/** provided that such works are identified as "derived from the RSA **/
|
||||
/** Data Security, Inc. MD5 Message-Digest Algorithm" in all **/
|
||||
/** material mentioning or referencing the derived work. **/
|
||||
/** **/
|
||||
/** RSA Data Security, Inc. makes no representations concerning **/
|
||||
/** either the merchantability of this software or the suitability **/
|
||||
/** of this software for any particular purpose. It is provided "as **/
|
||||
/** is" without express or implied warranty of any kind. **/
|
||||
/** **/
|
||||
/** These notices must be retained in any copies of any part of this **/
|
||||
/** documentation and/or software. **/
|
||||
/***********************************************************************/
|
||||
|
||||
#include "./include/radius_pub.h"
|
||||
#include "./include/radius_md5.h"
|
||||
|
||||
/***********************************************************************/
|
||||
/** Message-digest routines: **/
|
||||
/** To form the message digest for a message M **/
|
||||
/** (1) Initialize a context buffer mdContext using MD5Init **/
|
||||
/** (2) Call MD5Update on mdContext and M **/
|
||||
/** (3) Call MD5Final on mdContext **/
|
||||
/** The message digest is now in mdContext->digest[0...15] **/
|
||||
/***********************************************************************/
|
||||
|
||||
static unsigned char PADDING[64] =
|
||||
{
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
/* F, G, H and I are basic MD5 functions */
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits */
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
|
||||
/* Rotation is separate from addition to prevent recomputation */
|
||||
|
||||
#define FF(a, b, c, d, x, s, ac) \
|
||||
{\
|
||||
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define GG(a, b, c, d, x, s, ac) \
|
||||
{\
|
||||
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define HH(a, b, c, d, x, s, ac) \
|
||||
{\
|
||||
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define II(a, b, c, d, x, s, ac) \
|
||||
{\
|
||||
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
/* The routine MD5Init initializes the message-digest context
|
||||
mdContext. All fields are set to zero.
|
||||
*/
|
||||
|
||||
void radius_MD5Init (MD5_CTX *mdContext)
|
||||
{
|
||||
mdContext->i[0] = mdContext->i[1] = (UINT4)0;
|
||||
|
||||
/* Load magic initialization constants.*/
|
||||
mdContext->buf[0] = (UINT4)0x67452301;
|
||||
mdContext->buf[1] = (UINT4)0xefcdab89;
|
||||
mdContext->buf[2] = (UINT4)0x98badcfe;
|
||||
mdContext->buf[3] = (UINT4)0x10325476;
|
||||
}
|
||||
|
||||
/* The routine MD5Update updates the message-digest context to
|
||||
account for the presence of each of the characters inBuf[0..inLen-1]
|
||||
in the message whose digest is being computed.
|
||||
*/
|
||||
|
||||
void radius_MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)
|
||||
{
|
||||
UINT4 in[16];
|
||||
int mdi;
|
||||
unsigned int i, ii;
|
||||
|
||||
/*compute number of bytes mod 64*/
|
||||
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/*update number of bits*/
|
||||
if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
|
||||
mdContext->i[1]++;
|
||||
|
||||
mdContext->i[0] += ((UINT4)inLen << 3);
|
||||
mdContext->i[1] += ((UINT4)inLen >> 29);
|
||||
|
||||
#ifdef LITTLE_ENDIAN
|
||||
/* Speedup for little-endian machines suggested in MD5 report --P Karn */
|
||||
if(mdi == 0 && ((unsigned long)inBuf & 0x03) == 0)
|
||||
{
|
||||
while(inLen >= 64)
|
||||
{
|
||||
radius_MD5Transform(mdContext->buf,(UINT4 *)inBuf);
|
||||
inLen -= 64;
|
||||
inBuf += 64;
|
||||
}
|
||||
}
|
||||
#endif /* LITTLE_ENDIAN */
|
||||
|
||||
while (inLen--)
|
||||
{
|
||||
/* add new character to buffer, increment mdi */
|
||||
mdContext->in[mdi++] = *inBuf++;
|
||||
|
||||
/* transform if necessary */
|
||||
if (mdi == 0x40)
|
||||
{
|
||||
for (i = 0, ii = 0; i < 16; i++, ii += 4)
|
||||
in[i] = (((UINT4)mdContext->in[ii+3]) << 24) | (((UINT4)mdContext->in[ii+2]) << 16)
|
||||
| (((UINT4)mdContext->in[ii+1]) << 8) | ((UINT4)mdContext->in[ii]);
|
||||
|
||||
radius_MD5Transform (mdContext->buf, in);
|
||||
mdi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The routine MD5Final terminates the message-digest computation and
|
||||
ends with the desired message digest in mdContext->digest[0...15].
|
||||
*/
|
||||
void radius_MD5Final (MD5_CTX *mdContext)
|
||||
{
|
||||
UINT4 in[16];
|
||||
int mdi;
|
||||
unsigned int i, ii;
|
||||
unsigned int padLen;
|
||||
|
||||
/* save number of bits */
|
||||
in[14] = mdContext->i[0];
|
||||
in[15] = mdContext->i[1];
|
||||
|
||||
/* compute number of bytes mod 64 */
|
||||
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/* pad out to 56 mod 64 */
|
||||
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
|
||||
|
||||
radius_MD5Update(mdContext, PADDING, padLen);
|
||||
|
||||
/* append length in bits and transform */
|
||||
for (i = 0, ii = 0; i < 14; i++, ii += 4)
|
||||
in[i] = (((UINT4)mdContext->in[ii+3]) << 24) | (((UINT4)mdContext->in[ii+2]) << 16)
|
||||
| (((UINT4)mdContext->in[ii+1]) << 8) | ((UINT4)mdContext->in[ii]);
|
||||
|
||||
radius_MD5Transform (mdContext->buf, in);
|
||||
|
||||
/* store buffer in digest */
|
||||
for (i = 0, ii = 0; i < 4; i++, ii += 4)
|
||||
{
|
||||
mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
|
||||
mdContext->digest[ii+1] = (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
|
||||
mdContext->digest[ii+2] = (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
|
||||
mdContext->digest[ii+3] = (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef CPU386 /* Fast assembler version exists for 386/486 */
|
||||
/* Basic MD5 step. Transforms buf based on in.*/
|
||||
void radius_MD5Transform (UINT4 *buf, UINT4 *in)
|
||||
{
|
||||
UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
/* Round 1 */
|
||||
FF ( a, b, c, d, in[ 0], S11, 3614090360UL); /* 1 */
|
||||
FF ( d, a, b, c, in[ 1], S12, 3905402710UL); /* 2 */
|
||||
FF ( c, d, a, b, in[ 2], S13, 606105819UL); /* 3 */
|
||||
FF ( b, c, d, a, in[ 3], S14, 3250441966UL); /* 4 */
|
||||
FF ( a, b, c, d, in[ 4], S11, 4118548399UL); /* 5 */
|
||||
FF ( d, a, b, c, in[ 5], S12, 1200080426); /* 6 */ // not bigger than 2147483647
|
||||
FF ( c, d, a, b, in[ 6], S13, 2821735955UL); /* 7 */
|
||||
FF ( b, c, d, a, in[ 7], S14, 4249261313UL); /* 8 */
|
||||
FF ( a, b, c, d, in[ 8], S11, 1770035416); /* 9 */
|
||||
FF ( d, a, b, c, in[ 9], S12, 2336552879UL); /* 10 */
|
||||
FF ( c, d, a, b, in[10], S13, 4294925233UL); /* 11 */
|
||||
FF ( b, c, d, a, in[11], S14, 2304563134UL); /* 12 */
|
||||
FF ( a, b, c, d, in[12], S11, 1804603682); /* 13 */
|
||||
FF ( d, a, b, c, in[13], S12, 4254626195UL); /* 14 */
|
||||
FF ( c, d, a, b, in[14], S13, 2792965006UL); /* 15 */
|
||||
FF ( b, c, d, a, in[15], S14, 1236535329); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG ( a, b, c, d, in[ 1], S21, 4129170786UL); /* 17 */
|
||||
GG ( d, a, b, c, in[ 6], S22, 3225465664UL); /* 18 */
|
||||
GG ( c, d, a, b, in[11], S23, 643717713); /* 19 */
|
||||
GG ( b, c, d, a, in[ 0], S24, 3921069994UL); /* 20 */
|
||||
GG ( a, b, c, d, in[ 5], S21, 3593408605UL); /* 21 */
|
||||
GG ( d, a, b, c, in[10], S22, 38016083); /* 22 */
|
||||
GG ( c, d, a, b, in[15], S23, 3634488961UL); /* 23 */
|
||||
GG ( b, c, d, a, in[ 4], S24, 3889429448UL); /* 24 */
|
||||
GG ( a, b, c, d, in[ 9], S21, 568446438); /* 25 */
|
||||
GG ( d, a, b, c, in[14], S22, 3275163606UL); /* 26 */
|
||||
GG ( c, d, a, b, in[ 3], S23, 4107603335UL); /* 27 */
|
||||
GG ( b, c, d, a, in[ 8], S24, 1163531501); /* 28 */
|
||||
GG ( a, b, c, d, in[13], S21, 2850285829UL); /* 29 */
|
||||
GG ( d, a, b, c, in[ 2], S22, 4243563512UL); /* 30 */
|
||||
GG ( c, d, a, b, in[ 7], S23, 1735328473); /* 31 */
|
||||
GG ( b, c, d, a, in[12], S24, 2368359562UL); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH ( a, b, c, d, in[ 5], S31, 4294588738UL); /* 33 */
|
||||
HH ( d, a, b, c, in[ 8], S32, 2272392833UL); /* 34 */
|
||||
HH ( c, d, a, b, in[11], S33, 1839030562); /* 35 */
|
||||
HH ( b, c, d, a, in[14], S34, 4259657740UL); /* 36 */
|
||||
HH ( a, b, c, d, in[ 1], S31, 2763975236UL); /* 37 */
|
||||
HH ( d, a, b, c, in[ 4], S32, 1272893353); /* 38 */
|
||||
HH ( c, d, a, b, in[ 7], S33, 4139469664UL); /* 39 */
|
||||
HH ( b, c, d, a, in[10], S34, 3200236656UL); /* 40 */
|
||||
HH ( a, b, c, d, in[13], S31, 681279174); /* 41 */
|
||||
HH ( d, a, b, c, in[ 0], S32, 3936430074UL); /* 42 */
|
||||
HH ( c, d, a, b, in[ 3], S33, 3572445317UL); /* 43 */
|
||||
HH ( b, c, d, a, in[ 6], S34, 76029189); /* 44 */
|
||||
HH ( a, b, c, d, in[ 9], S31, 3654602809UL); /* 45 */
|
||||
HH ( d, a, b, c, in[12], S32, 3873151461UL); /* 46 */
|
||||
HH ( c, d, a, b, in[15], S33, 530742520); /* 47 */
|
||||
HH ( b, c, d, a, in[ 2], S34, 3299628645UL); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
II ( a, b, c, d, in[ 0], S41, 4096336452UL); /* 49 */
|
||||
II ( d, a, b, c, in[ 7], S42, 1126891415); /* 50 */
|
||||
II ( c, d, a, b, in[14], S43, 2878612391UL); /* 51 */
|
||||
II ( b, c, d, a, in[ 5], S44, 4237533241UL); /* 52 */
|
||||
II ( a, b, c, d, in[12], S41, 1700485571); /* 53 */
|
||||
II ( d, a, b, c, in[ 3], S42, 2399980690UL); /* 54 */
|
||||
II ( c, d, a, b, in[10], S43, 4293915773UL); /* 55 */
|
||||
II ( b, c, d, a, in[ 1], S44, 2240044497UL); /* 56 */
|
||||
II ( a, b, c, d, in[ 8], S41, 1873313359); /* 57 */
|
||||
II ( d, a, b, c, in[15], S42, 4264355552UL); /* 58 */
|
||||
II ( c, d, a, b, in[ 6], S43, 2734768916UL); /* 59 */
|
||||
II ( b, c, d, a, in[13], S44, 1309151649); /* 60 */
|
||||
II ( a, b, c, d, in[ 4], S41, 4149444226UL); /* 61 */
|
||||
II ( d, a, b, c, in[11], S42, 3174756917UL); /* 62 */
|
||||
II ( c, d, a, b, in[ 2], S43, 718787259); /* 63 */
|
||||
II ( b, c, d, a, in[ 9], S44, 3951481745UL); /* 64 */
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
#else /* CPU386 */
|
||||
/* Fast 386 Borland C inline assembler version of the MD5Transform() function
|
||||
* from the RSA Data Security, Inc, MD5 Message Digest Algorithm.
|
||||
*
|
||||
* This version uses native 32 bit registers, so it needs a 386 or 486 CPU.
|
||||
*
|
||||
* Because this function does *lots* of 32-bit operations, this version is
|
||||
* MUCH faster than the reference C version compiled with a garden-
|
||||
* variety 16-bit MS-DOS C compiler.
|
||||
*
|
||||
* Written and placed into the public domain on
|
||||
* 22 February 1992 by Phil Karn, KA9Q
|
||||
*/
|
||||
|
||||
/* I really shouldn't have to do this explicitly... */
|
||||
#ifdef __COMPACT__
|
||||
|
||||
asm .MODEL COMPACT
|
||||
|
||||
#elif __HUGE__
|
||||
|
||||
asm .MODEL HUGE
|
||||
|
||||
#elif __LARGE__
|
||||
|
||||
asm .MODEL LARGE
|
||||
|
||||
#elif __MEDIUM__
|
||||
|
||||
asm .MODEL MEDIUM
|
||||
|
||||
#elif __SMALL__
|
||||
|
||||
asm .MODEL SMALL
|
||||
|
||||
#elif __TINY__
|
||||
|
||||
asm .MODEL TINY
|
||||
|
||||
#endif
|
||||
|
||||
/* Code sequence common to all four rounds.
|
||||
|
||||
* evaluates a = b + (a + edi + x + t) <<< s
|
||||
|
||||
* Assumes a,b are registers, s,t are immediate constants
|
||||
|
||||
* The 'lea' instruction is just a fast way to compute "a = a+t+edi"
|
||||
|
||||
*/
|
||||
|
||||
#define COM(a,b,x,s,t)\
|
||||
|
||||
asm lea a,t[a+edi];\
|
||||
|
||||
asm add a,x;\
|
||||
|
||||
asm rol a,s;\
|
||||
|
||||
asm add a,b;
|
||||
|
||||
|
||||
|
||||
/* Round 1 functions */
|
||||
|
||||
/* edi = F(x,y,z) = (x & y) | (~x & z) */
|
||||
|
||||
#define F(x,y,z)\
|
||||
|
||||
asm mov edi,x;\
|
||||
|
||||
asm and edi,y;\
|
||||
|
||||
asm mov esi,x;\
|
||||
|
||||
asm not esi;\
|
||||
|
||||
asm and esi,z;\
|
||||
|
||||
asm or edi,esi
|
||||
|
||||
|
||||
|
||||
/* a = b + ((a + F(x,y,z) + x + t) <<< s); */
|
||||
|
||||
#define FF(a,b,c,d,x,s,t)\
|
||||
|
||||
F(b,c,d);\
|
||||
|
||||
COM(a,b,x,s,t)
|
||||
|
||||
|
||||
|
||||
/* Round 2 functions */
|
||||
|
||||
/* edi = G(x,y,z) = F(z,x,y) = (x & z) | (y & ~z) */
|
||||
|
||||
#define G(x,y,z) F(z,x,y)
|
||||
|
||||
|
||||
|
||||
/* a = b + ((a + G(b,c,d) + x + t) <<< s) */
|
||||
|
||||
#define GG(a,b,c,d,x,s,t)\
|
||||
|
||||
G(b,c,d);\
|
||||
|
||||
COM(a,b,x,s,t)
|
||||
|
||||
|
||||
|
||||
/* Round 3 functions */
|
||||
|
||||
/* edi = H(x,y,z) = x ^ y ^ z */
|
||||
|
||||
#define H(x,y,z)\
|
||||
|
||||
asm mov edi,x;\
|
||||
|
||||
asm xor edi,y;\
|
||||
|
||||
asm xor edi,z
|
||||
|
||||
|
||||
|
||||
/* a = b + ((a + H(b,c,d) + x + t) <<< s) */
|
||||
|
||||
#define HH(a,b,c,d,x,s,t)\
|
||||
|
||||
H(b,c,d);\
|
||||
|
||||
COM(a,b,x,s,t)
|
||||
|
||||
|
||||
|
||||
/* Round 4 functions */
|
||||
|
||||
/* edi = I(x,y,z) = y ^ (x | ~z) */
|
||||
|
||||
#define I(x,y,z)\
|
||||
|
||||
asm mov edi,z;\
|
||||
|
||||
asm not edi;\
|
||||
|
||||
asm or edi,x;\
|
||||
|
||||
asm xor edi,y
|
||||
|
||||
|
||||
|
||||
/* a = b + ((a + I(b,c,d) + x + t) <<< s) */
|
||||
|
||||
#define II(a,b,c,d,x,s,t)\
|
||||
|
||||
I(b,c,d);\
|
||||
|
||||
COM(a,b,x,s,t)
|
||||
|
||||
|
||||
|
||||
#define A eax
|
||||
|
||||
#define B ebx
|
||||
|
||||
#define C ecx
|
||||
|
||||
#define D edx
|
||||
|
||||
|
||||
|
||||
void radius_MD5Transform(UINT4 *buf,UINT4 *input)
|
||||
{
|
||||
asm .386; /* Allow use of 32-bit general registers */
|
||||
|
||||
/* Save caller's registers */
|
||||
|
||||
asm push si;
|
||||
|
||||
asm push di;
|
||||
|
||||
asm push es;
|
||||
|
||||
asm if @DataSize NE 0
|
||||
|
||||
asm push ds;
|
||||
|
||||
asm endif
|
||||
|
||||
|
||||
|
||||
/* Get buf argument */
|
||||
|
||||
asm if @DataSize NE 0
|
||||
|
||||
asm lds si,buf;
|
||||
|
||||
asm else
|
||||
|
||||
asm mov si,buf;
|
||||
|
||||
asm endif
|
||||
|
||||
asm mov A,dword ptr si[0*4]; /* A = buf[0] */
|
||||
|
||||
asm mov B,dword ptr si[1*4]; /* B = buf[1] */
|
||||
|
||||
asm mov C,dword ptr si[2*4]; /* C = buf[2] */
|
||||
|
||||
asm mov D,dword ptr si[3*4]; /* D = buf[3] */
|
||||
|
||||
/* Warning: This makes our other args inaccessible until bp
|
||||
* is restored!
|
||||
*/
|
||||
asm push bp;
|
||||
|
||||
asm les bp,input
|
||||
|
||||
/* Round 1. The *4 factors in the subscripts to bp account for the
|
||||
* byte offsets of each long element in the input array.
|
||||
*/
|
||||
|
||||
#define S11 7
|
||||
|
||||
#define S12 12
|
||||
|
||||
#define S13 17
|
||||
|
||||
#define S14 22
|
||||
|
||||
FF(A,B,C,D,es:bp[ 0*4],S11,3614090360); /* 1 */
|
||||
|
||||
FF(D,A,B,C,es:bp[ 1*4],S12,3905402710); /* 2 */
|
||||
|
||||
FF(C,D,A,B,es:bp[ 2*4],S13, 606105819); /* 3 */
|
||||
|
||||
FF(B,C,D,A,es:bp[ 3*4],S14,3250441966); /* 4 */
|
||||
|
||||
FF(A,B,C,D,es:bp[ 4*4],S11,4118548399); /* 5 */
|
||||
|
||||
FF(D,A,B,C,es:bp[ 5*4],S12,1200080426); /* 6 */
|
||||
|
||||
FF(C,D,A,B,es:bp[ 6*4],S13,2821735955); /* 7 */
|
||||
|
||||
FF(B,C,D,A,es:bp[ 7*4],S14,4249261313); /* 8 */
|
||||
|
||||
FF(A,B,C,D,es:bp[ 8*4],S11,1770035416); /* 9 */
|
||||
|
||||
FF(D,A,B,C,es:bp[ 9*4],S12,2336552879); /* 10 */
|
||||
|
||||
FF(C,D,A,B,es:bp[10*4],S13,4294925233); /* 11 */
|
||||
|
||||
FF(B,C,D,A,es:bp[11*4],S14,2304563134); /* 12 */
|
||||
|
||||
FF(A,B,C,D,es:bp[12*4],S11,1804603682); /* 13 */
|
||||
|
||||
FF(D,A,B,C,es:bp[13*4],S12,4254626195); /* 14 */
|
||||
|
||||
FF(C,D,A,B,es:bp[14*4],S13,2792965006); /* 15 */
|
||||
|
||||
FF(B,C,D,A,es:bp[15*4],S14,1236535329); /* 16 */
|
||||
|
||||
|
||||
|
||||
/* Round 2 */
|
||||
|
||||
#define S21 5
|
||||
|
||||
#define S22 9
|
||||
|
||||
#define S23 14
|
||||
|
||||
#define S24 20
|
||||
|
||||
GG(A,B,C,D,es:bp[ 1*4],S21,4129170786); /* 17 */
|
||||
|
||||
GG(D,A,B,C,es:bp[ 6*4],S22,3225465664); /* 18 */
|
||||
|
||||
GG(C,D,A,B,es:bp[11*4],S23, 643717713); /* 19 */
|
||||
|
||||
GG(B,C,D,A,es:bp[ 0*4],S24,3921069994); /* 20 */
|
||||
|
||||
GG(A,B,C,D,es:bp[ 5*4],S21,3593408605); /* 21 */
|
||||
|
||||
GG(D,A,B,C,es:bp[10*4],S22, 38016083); /* 22 */
|
||||
|
||||
GG(C,D,A,B,es:bp[15*4],S23,3634488961); /* 23 */
|
||||
|
||||
GG(B,C,D,A,es:bp[ 4*4],S24,3889429448); /* 24 */
|
||||
|
||||
GG(A,B,C,D,es:bp[ 9*4],S21, 568446438); /* 25 */
|
||||
|
||||
GG(D,A,B,C,es:bp[14*4],S22,3275163606); /* 26 */
|
||||
|
||||
GG(C,D,A,B,es:bp[ 3*4],S23,4107603335); /* 27 */
|
||||
|
||||
GG(B,C,D,A,es:bp[ 8*4],S24,1163531501); /* 28 */
|
||||
|
||||
GG(A,B,C,D,es:bp[13*4],S21,2850285829); /* 29 */
|
||||
|
||||
GG(D,A,B,C,es:bp[ 2*4],S22,4243563512); /* 30 */
|
||||
|
||||
GG(C,D,A,B,es:bp[ 7*4],S23,1735328473); /* 31 */
|
||||
|
||||
GG(B,C,D,A,es:bp[12*4],S24,2368359562); /* 32 */
|
||||
|
||||
|
||||
|
||||
/* Round 3 */
|
||||
|
||||
#define S31 4
|
||||
|
||||
#define S32 11
|
||||
|
||||
#define S33 16
|
||||
|
||||
#define S34 23
|
||||
|
||||
HH(A,B,C,D,es:bp[ 5*4],S31,4294588738); /* 33 */
|
||||
|
||||
HH(D,A,B,C,es:bp[ 8*4],S32,2272392833); /* 34 */
|
||||
|
||||
HH(C,D,A,B,es:bp[11*4],S33,1839030562); /* 35 */
|
||||
|
||||
HH(B,C,D,A,es:bp[14*4],S34,4259657740); /* 36 */
|
||||
|
||||
HH(A,B,C,D,es:bp[ 1*4],S31,2763975236); /* 37 */
|
||||
|
||||
HH(D,A,B,C,es:bp[ 4*4],S32,1272893353); /* 38 */
|
||||
|
||||
HH(C,D,A,B,es:bp[ 7*4],S33,4139469664); /* 39 */
|
||||
|
||||
HH(B,C,D,A,es:bp[10*4],S34,3200236656); /* 40 */
|
||||
|
||||
HH(A,B,C,D,es:bp[13*4],S31, 681279174); /* 41 */
|
||||
|
||||
HH(D,A,B,C,es:bp[ 0*4],S32,3936430074); /* 42 */
|
||||
|
||||
HH(C,D,A,B,es:bp[ 3*4],S33,3572445317); /* 43 */
|
||||
|
||||
HH(B,C,D,A,es:bp[ 6*4],S34, 76029189); /* 44 */
|
||||
|
||||
HH(A,B,C,D,es:bp[ 9*4],S31,3654602809); /* 45 */
|
||||
|
||||
HH(D,A,B,C,es:bp[12*4],S32,3873151461); /* 46 */
|
||||
|
||||
HH(C,D,A,B,es:bp[15*4],S33, 530742520); /* 47 */
|
||||
|
||||
HH(B,C,D,A,es:bp[ 2*4],S34,3299628645); /* 48 */
|
||||
|
||||
|
||||
|
||||
/* Round 4 */
|
||||
|
||||
#define S41 6
|
||||
|
||||
#define S42 10
|
||||
|
||||
#define S43 15
|
||||
|
||||
#define S44 21
|
||||
|
||||
II(A,B,C,D,es:bp[ 0*4],S41,4096336452); /* 49 */
|
||||
|
||||
II(D,A,B,C,es:bp[ 7*4],S42,1126891415); /* 50 */
|
||||
|
||||
II(C,D,A,B,es:bp[14*4],S43,2878612391); /* 51 */
|
||||
|
||||
II(B,C,D,A,es:bp[ 5*4],S44,4237533241); /* 52 */
|
||||
|
||||
II(A,B,C,D,es:bp[12*4],S41,1700485571); /* 53 */
|
||||
|
||||
II(D,A,B,C,es:bp[ 3*4],S42,2399980690); /* 54 */
|
||||
|
||||
II(C,D,A,B,es:bp[10*4],S43,4293915773); /* 55 */
|
||||
|
||||
II(B,C,D,A,es:bp[ 1*4],S44,2240044497); /* 56 */
|
||||
|
||||
II(A,B,C,D,es:bp[ 8*4],S41,1873313359); /* 57 */
|
||||
|
||||
II(D,A,B,C,es:bp[15*4],S42,4264355552); /* 58 */
|
||||
|
||||
II(C,D,A,B,es:bp[ 6*4],S43,2734768916); /* 59 */
|
||||
|
||||
II(B,C,D,A,es:bp[13*4],S44,1309151649); /* 60 */
|
||||
|
||||
II(A,B,C,D,es:bp[ 4*4],S41,4149444226); /* 61 */
|
||||
|
||||
II(D,A,B,C,es:bp[11*4],S42,3174756917); /* 62 */
|
||||
|
||||
II(C,D,A,B,es:bp[ 2*4],S43, 718787259); /* 63 */
|
||||
|
||||
II(B,C,D,A,es:bp[ 9*4],S44,3951481745); /* 64 */
|
||||
|
||||
|
||||
|
||||
asm pop bp; /* We can address our args again */
|
||||
|
||||
asm if @DataSize NE 0
|
||||
|
||||
asm lds si,buf
|
||||
|
||||
asm else
|
||||
|
||||
asm mov si,buf;
|
||||
|
||||
asm endif
|
||||
|
||||
asm add dword ptr si[0*4],A; /* buf[0] += A */
|
||||
|
||||
asm add dword ptr si[1*4],B; /* buf[1] += B */
|
||||
|
||||
asm add dword ptr si[2*4],C; /* buf[2] += C */
|
||||
|
||||
asm add dword ptr si[3*4],D; /* buf[3] += D */
|
||||
|
||||
|
||||
|
||||
/* Restore caller's registers */
|
||||
|
||||
asm if @DataSize NE 0
|
||||
|
||||
asm pop ds
|
||||
|
||||
asm endif
|
||||
|
||||
|
||||
|
||||
asm pop es;
|
||||
|
||||
asm pop di;
|
||||
|
||||
asm pop si;
|
||||
|
||||
}
|
||||
|
||||
#endif /* CPU386 */
|
||||
|
||||
static void radius_MDPrint (char *dest, unsigned char digest[16])
|
||||
{
|
||||
unsigned int i;
|
||||
char tmp[4];
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
sprintf (tmp, "%02x", digest[i]);
|
||||
strcat(dest, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static void radius_MDPrint_Hex(char *dest, unsigned char digest[16])
|
||||
{
|
||||
memcpy(dest, digest, 16);
|
||||
}
|
||||
|
||||
void radius_get_md5_str(char *dest, char *org, int len)
|
||||
{
|
||||
MD5_CTX context;
|
||||
|
||||
strcpy(dest, "");
|
||||
|
||||
radius_MD5Init (&context);
|
||||
|
||||
radius_MD5Update (&context, (unsigned char*)org, (unsigned int)len);
|
||||
|
||||
radius_MD5Final (&context);// MD5Final (digest, &context);
|
||||
|
||||
radius_MDPrint (dest, context.digest);
|
||||
}
|
||||
|
||||
void radius_get_md5_hex(char *dest, char *org, int len)
|
||||
{
|
||||
MD5_CTX context;
|
||||
|
||||
bzero(dest, 16);
|
||||
|
||||
radius_MD5Init (&context);
|
||||
|
||||
radius_MD5Update (&context, (unsigned char*)org, (unsigned int)len);
|
||||
|
||||
radius_MD5Final (&context);// MD5Final (digest, &context);
|
||||
|
||||
radius_MDPrint_Hex (dest, context.digest);
|
||||
}
|
||||
|
||||
void radius_hmac_md5_calc(char *dest, char *org, int len, BYTE *pad)
|
||||
{
|
||||
MD5_CTX context;
|
||||
|
||||
bzero(dest, 16);
|
||||
|
||||
radius_MD5Init (&context);
|
||||
|
||||
radius_MD5Update(&context, pad, 64);/* start with inner pad */
|
||||
|
||||
radius_MD5Update (&context, (unsigned char*)org, (unsigned int)len);
|
||||
|
||||
radius_MD5Final (&context);// MD5Final (digest, &context);
|
||||
|
||||
radius_MDPrint_Hex (dest, context.digest);
|
||||
}
|
||||
|
||||
void radius_get_hmac_md5_hex(BYTE *dest, BYTE *org, int org_len, BYTE *key, int key_len)
|
||||
{
|
||||
int i;
|
||||
BYTE k_ipad[65] = ""; /* inner padding-key XORd with ipad*/
|
||||
BYTE k_opad[65] = ""; /* outer padding-key XORd with opad*/
|
||||
BYTE tk[16];
|
||||
BYTE calc_key[65] = "";
|
||||
int calc_key_len = 0;
|
||||
|
||||
/* if key is longer than 64 bytes reset it to key=MD5(key) */
|
||||
if (key_len > 64)
|
||||
{
|
||||
radius_get_md5_hex((char*)tk, (char*)key, key_len);
|
||||
|
||||
memcpy(calc_key, tk, 16);
|
||||
calc_key_len = 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(calc_key, key, key_len);
|
||||
calc_key_len = key_len;
|
||||
}
|
||||
|
||||
/* the HMAC_MD5 transform looks like:
|
||||
*
|
||||
* MD5(K XOR opad, MD5(K XOR ipad, org))
|
||||
*
|
||||
* where K is an n byte key
|
||||
* ipad is the byte 0x36 repeated 64 times
|
||||
* opad is the byte 0x5c repeated 64 times
|
||||
* and text is the data being protected
|
||||
*/
|
||||
|
||||
/* start out by storing key in pads */
|
||||
bzero(k_ipad, sizeof k_ipad);
|
||||
bzero(k_opad, sizeof k_opad);
|
||||
|
||||
bcopy(calc_key, k_ipad, calc_key_len);
|
||||
bcopy(calc_key, k_opad, calc_key_len);
|
||||
|
||||
/* XOR key with ipad and opad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
{
|
||||
k_ipad[i] ^= 0x36;
|
||||
k_opad[i] ^= 0x5c;
|
||||
}
|
||||
|
||||
/*perform inner MD5*/
|
||||
radius_hmac_md5_calc((char*)tk, (char*)org, org_len, k_ipad);
|
||||
|
||||
/* perform outer MD5*/
|
||||
radius_hmac_md5_calc((char*)dest, (char*)tk, 16, k_opad);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
***********************************************************************
|
||||
|
||||
** End of md5.c **
|
||||
|
||||
******************************** (cut) ********************************
|
||||
|
||||
*/
|
||||
|
||||
126
plat/radius/src/radius_transport.c
Normal file
126
plat/radius/src/radius_transport.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "./include/radius_pub.h"
|
||||
|
||||
int radius_recv_udp_msg(void)
|
||||
{
|
||||
struct sockaddr_in radius_src_addr;
|
||||
int i, len, addr_len = sizeof(struct sockaddr);
|
||||
RADIUS_ADDR addr;
|
||||
int nas_id;
|
||||
|
||||
for (i = 0; i < RADIUS_MAX_UDP_MSG_GET_TIMES; i++)
|
||||
{
|
||||
len = recvfrom(radius_udp_access_socket_fd, radius_udp_msg_recv_buf, RADIUS_MAX_LEN_OF_UDP_MSG, \
|
||||
0, (struct sockaddr *)&radius_src_addr, (socklen_t*)&addr_len);
|
||||
if (len < 0)
|
||||
break;
|
||||
|
||||
if (len >= RADIUS_MAX_LEN_OF_UDP_MSG)
|
||||
continue;
|
||||
|
||||
memset(radius_udp_msg_recv_buf + len, 0, RADIUS_MAX_LEN_OF_UDP_MSG - len);
|
||||
|
||||
addr.port = ntohs(radius_src_addr.sin_port);
|
||||
addr.addr.ipV4 = radius_src_addr.sin_addr.s_addr;
|
||||
|
||||
if ((nas_id = radius_accord_ip_search_nas_info(radius_src_addr.sin_addr.s_addr)) < 0)
|
||||
{
|
||||
radius_log_warn("%s: recv msg from %s, no such nas ip\r\n", __FUNCTION__, inet_ntoa(radius_src_addr.sin_addr));
|
||||
continue;
|
||||
}
|
||||
|
||||
radius_udp_msg_handling(radius_udp_msg_recv_buf, len, &addr, nas_id);
|
||||
}
|
||||
|
||||
for (i = 0; i < RADIUS_MAX_UDP_MSG_GET_TIMES; i++)
|
||||
{
|
||||
len = recvfrom(radius_udp_account_socket_fd, radius_udp_msg_recv_buf, RADIUS_MAX_LEN_OF_UDP_MSG, \
|
||||
0, (struct sockaddr *)&radius_src_addr, (socklen_t*)&addr_len);
|
||||
if (len < 0)
|
||||
break;
|
||||
|
||||
if (len >= RADIUS_MAX_LEN_OF_UDP_MSG)
|
||||
continue;
|
||||
|
||||
memset(radius_udp_msg_recv_buf + len, 0, RADIUS_MAX_LEN_OF_UDP_MSG - len);
|
||||
|
||||
addr.port = ntohs(radius_src_addr.sin_port);
|
||||
addr.addr.ipV4 = radius_src_addr.sin_addr.s_addr;
|
||||
|
||||
if ((nas_id = radius_accord_ip_search_nas_info(radius_src_addr.sin_addr.s_addr)) < 0)
|
||||
{
|
||||
radius_log_warn("%s: recv msg from %s, no such nas ip\r\n", __FUNCTION__, inet_ntoa(radius_src_addr.sin_addr));
|
||||
continue;
|
||||
}
|
||||
|
||||
radius_udp_msg_handling(radius_udp_msg_recv_buf, len, &addr, nas_id);
|
||||
}
|
||||
|
||||
for (i = 0; i < RADIUS_MAX_UDP_MSG_GET_TIMES; i++)
|
||||
{
|
||||
len = recvfrom(radius_udp_disconnect_socket_fd, radius_udp_msg_recv_buf, RADIUS_MAX_LEN_OF_UDP_MSG, \
|
||||
0, (struct sockaddr *)&radius_src_addr, (socklen_t*)&addr_len);
|
||||
if (len < 0)
|
||||
break;
|
||||
|
||||
if (len >= RADIUS_MAX_LEN_OF_UDP_MSG)
|
||||
continue;
|
||||
|
||||
memset(radius_udp_msg_recv_buf + len, 0, RADIUS_MAX_LEN_OF_UDP_MSG - len);
|
||||
|
||||
addr.port = ntohs(radius_src_addr.sin_port);
|
||||
addr.addr.ipV4 = radius_src_addr.sin_addr.s_addr;
|
||||
|
||||
if ((nas_id = radius_accord_ip_search_nas_info(radius_src_addr.sin_addr.s_addr)) < 0)
|
||||
{
|
||||
radius_log_warn("%s: recv msg from %s, no such nas ip\r\n", __FUNCTION__, inet_ntoa(radius_src_addr.sin_addr));
|
||||
continue;
|
||||
}
|
||||
|
||||
radius_udp_msg_handling(radius_udp_msg_recv_buf, len, &addr, nas_id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radius_send_udp_msg(int pid)
|
||||
{
|
||||
int ret;
|
||||
int len;
|
||||
RADIUS_PID *pid_ptr;
|
||||
struct sockaddr_in radius_dst_addr;
|
||||
int socket_fd;
|
||||
|
||||
pid_ptr = radius_get_pid_ptr(pid);
|
||||
|
||||
len = pid_ptr->msg_len;
|
||||
|
||||
if (len >= RADIUS_MAX_LEN_OF_MSG)
|
||||
{
|
||||
radius_log_err("%s: msg len=%d\r\n", __FUNCTION__, pid_ptr->msg_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (radius_set_udp_dest_addr(&radius_dst_addr, &pid_ptr->peer_addr) < 0)
|
||||
{
|
||||
radius_log_err("%s: set destination address fail, pid=%d, dest_port=%d, dest_ip=0x%X\r\n", __FUNCTION__, pid, pid_ptr->peer_addr.port, pid_ptr->peer_addr.addr.ipV4);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((socket_fd = radius_get_sock_fd_according_msg_type(pid_ptr->sd_msg_type)) < 0)
|
||||
{
|
||||
radius_log_err("%s: msg type=%d get sock fd fail\r\n", __FUNCTION__, pid_ptr->sd_msg_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = sendto(socket_fd, pid_ptr->msg, len, 0, (struct sockaddr *)&radius_dst_addr, sizeof(struct sockaddr_in));
|
||||
|
||||
radius_log_send_recv_msg(pid_ptr->msg, len, &pid_ptr->peer_addr, pid_ptr->sd_msg_type, RADIUS_SEND_MSG_FLAG);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
radius_log_err("%s: send msg fail\r\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
101
plat/radius/ut/Makefile
Normal file
101
plat/radius/ut/Makefile
Normal file
@@ -0,0 +1,101 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile for module template : V1.6.3 ##
|
||||
## ##
|
||||
## Created : Wei Liu 07/04/11 ##
|
||||
## Revision: [Last]Wei Liu 07/07/07 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project correlation(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## MODULE= [Module Name]
|
||||
## TYPE = app/plat => Module Type
|
||||
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
|
||||
|
||||
## BUILD = lib/exef => Output file format
|
||||
## CFG = debug/release => Build Configuration
|
||||
|
||||
## SRC_PATH = [Source file path]
|
||||
## INC_PATH = [Include file path]
|
||||
## APP_PATH = [App Module path]
|
||||
## PLT_PATH = [Plat Module path]
|
||||
|
||||
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
|
||||
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
|
||||
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
|
||||
|
||||
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
|
||||
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
|
||||
## snmp iptrans debug sccp public
|
||||
##
|
||||
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
|
||||
## LIB_ADD e.g. = -liba3a8 -lm
|
||||
|
||||
## OBJ_ADD = [Extend third party object files needed]
|
||||
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
MODULE = radiustest
|
||||
TYPE = app
|
||||
|
||||
DBUG_FLAGS_ADD = -D_LKSCTP
|
||||
RELS_FLAGS_ADD = -D_LKSCTP
|
||||
|
||||
##Default commonly as below
|
||||
|
||||
BUILD = exef
|
||||
CFG = debug
|
||||
|
||||
APP_LIB = mnp vlr hlr msc vlr smsc ssf ae pps aas opr iif
|
||||
|
||||
PLT_LIB = radius megaco scf sccp haepub aif mgc_v2 mgcp rtp \
|
||||
8ecp isup bicc smpp xapp tcap sccp mtp3 m2ua \
|
||||
debug snmp iptrans public pal isdn
|
||||
|
||||
LIB_ADD = -L../../../mss/ae/src/lib -lpubfunc \
|
||||
-la3a8 -ldl -lpopt -lncurses -L/usr/lib -lsrfvar -L/usr/local/lib -lcunit
|
||||
|
||||
SRC_PATH = ./
|
||||
INC_PATH = ./
|
||||
PLT_PATH = ../../../plat
|
||||
APP_PATH = ../../../mss
|
||||
|
||||
OBJ_ADD =
|
||||
TEST_OBJ_PATH = ./obj
|
||||
|
||||
PREPROC_CMD = cd ../;make rebuild; cd ./ut ;##cd ../../../plat;make rebuild CCFLAG_SWITCH=on DBUG_FLAGS_ADD+=-DEBUG_TEST;cd -; cd ../;make rebuild; cd ./ut
|
||||
POSTPROC_CMD =
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make configuration(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## CCFLAG_SWITCH = on/off => gcc flag show on/off
|
||||
## COVER_NEED = yes/no => PTF cover report needed
|
||||
## COVER_REPORT_PATH = [path ] => PTF cover report path
|
||||
|
||||
CCFLAG_SWITCH = off
|
||||
COVER_NEED = no
|
||||
COVER_REPORT_PATH = ./output
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## include makefile.rules (Do not change)
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.rules
|
||||
49
plat/radius/ut/radius_test_main.c
Normal file
49
plat/radius/ut/radius_test_main.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//#include "../src/include/megaco_pub.h"
|
||||
#include "radius_unit_test.h"
|
||||
|
||||
#include "/usr/local/include/CUnit/Basic.h"
|
||||
#include "/usr/local/include/CUnit/Automated.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// signal(SIGSEGV, &dump);
|
||||
CU_pSuite pSuite1 = NULL;
|
||||
CU_pSuite pSuite2 = NULL;
|
||||
CU_pSuite pSuite3 = NULL;
|
||||
|
||||
/* initialize the CUnit test registry */
|
||||
if (CUE_SUCCESS != CU_initialize_registry())
|
||||
return CU_get_error();
|
||||
|
||||
/* add a suite to the registry */
|
||||
pSuite1 = CU_add_suite("function test of radius", test_radius_init, NULL);
|
||||
|
||||
if (NULL == pSuite1)
|
||||
{
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
/* add the tests to the suite */
|
||||
if ((NULL == CU_add_test(pSuite1, "code test of radius", test_radius))
|
||||
)
|
||||
{
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
/* Run all tests using the CUnit Basic interface */
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
// CU_automated_run_tests();
|
||||
CU_list_tests_to_file();
|
||||
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
157
plat/radius/ut/radius_unit_test.c
Normal file
157
plat/radius/ut/radius_unit_test.c
Normal file
@@ -0,0 +1,157 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../src/include/radius_if.h"
|
||||
|
||||
#include "/usr/local/include/CUnit/CUnit.h"
|
||||
|
||||
int test_radius_ind(WORD *usr_pid, WORD pid, RADIUS_MSG *msg_pdu)
|
||||
{
|
||||
static int count = 0;
|
||||
int i;
|
||||
int num;
|
||||
BYTE str[64] = "";
|
||||
BYTE tmp[4] = "";
|
||||
RADIUS_MSG pdu;
|
||||
RADIUS_ACCESS_REQUEST *access_request;
|
||||
RADIUS_ACCESS_ACCEPT *access_accept;
|
||||
RADIUS_VENDOR_SPECIFIC *vendor_specific;
|
||||
RADIUS_VENDOR_ATTRIBUTE_3GPP2_PPAC *ppac;
|
||||
RADIUS_VENDOR_ATTRIBUTE_3GPP2_PPAQ *ppaq;
|
||||
RADIUS_DISCONNECT_REQUEST *disconnect_request;
|
||||
RADIUS_ADDR addr;
|
||||
RADIUS_ATTRIBUTE_REPLY_MESSAGE *reply_message;
|
||||
|
||||
*usr_pid = 0;
|
||||
|
||||
if (msg_pdu->msg_type != RADIUS_MSG_TYPE_ACCESS_REQUEST)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
access_request = &msg_pdu->msg.access_request;
|
||||
|
||||
if (access_request->user_password.flag == 1)
|
||||
{
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
sprintf(tmp, "%02x", access_request->user_password.user_password.value[i]);
|
||||
strcat(str, tmp);
|
||||
}
|
||||
|
||||
printf("user password=%s\r\n", str);
|
||||
}
|
||||
|
||||
memset(&pdu, 0, sizeof(RADIUS_MSG));
|
||||
|
||||
pdu.msg_type = RADIUS_MSG_TYPE_ACCESS_ACCEPT;
|
||||
|
||||
access_accept = &pdu.msg.access_accept;
|
||||
|
||||
vendor_specific = &access_accept->vendor_specific;
|
||||
|
||||
num = vendor_specific->num;
|
||||
|
||||
vendor_specific->vendor_specific[num].flag = 1;
|
||||
|
||||
vendor_specific->vendor_specific[num].vendor_type = RADIUS_VENDOR_TYPE_3GPP2_PPAC;
|
||||
|
||||
ppac = &vendor_specific->vendor_specific[num].attribute_3gpp2.ppac;
|
||||
|
||||
ppac->sfs.flag = 1;
|
||||
ppac->sfs.sfs = 2;//ppac->sfs.sfs = 1;//
|
||||
|
||||
vendor_specific->num++;
|
||||
|
||||
num = vendor_specific->num;
|
||||
|
||||
vendor_specific->vendor_specific[num].vendor_type = RADIUS_VENDOR_TYPE_3GPP2_PPAQ;
|
||||
|
||||
ppaq = &vendor_specific->vendor_specific[num].attribute_3gpp2.ppaq;
|
||||
|
||||
ppaq->qid.flag = 1;
|
||||
ppaq->qid.qid.value = 9;
|
||||
|
||||
/* ppaq->vq.flag = 1;
|
||||
ppaq->vq.vq.integer = (count + 1) * 102400;
|
||||
ppaq->vq.vq.exponent = 1;
|
||||
|
||||
ppaq->vt.flag = 1;
|
||||
ppaq->vt.vt.integer = (count + 1) * 102400 - 10240;
|
||||
ppaq->vt.vt.exponent = 1;*/
|
||||
|
||||
ppaq->dq.flag = 1;
|
||||
ppaq->dq.dq.value = (count + 1) * 25;
|
||||
|
||||
ppaq->dt.flag = 1;
|
||||
ppaq->dt.dt.value = (count + 1) * 25 - 7;
|
||||
|
||||
vendor_specific->num++;
|
||||
|
||||
access_accept->message_authenticator.flag = 1;
|
||||
|
||||
radius_send_access_accept(0, pid, 0, &pdu);
|
||||
|
||||
count++;
|
||||
|
||||
if (count == 3)
|
||||
{
|
||||
memset(&pdu, 0, sizeof(RADIUS_MSG));
|
||||
|
||||
disconnect_request = &pdu.msg.disconnect_request;
|
||||
|
||||
num = disconnect_request->reply_message.num;
|
||||
|
||||
reply_message = &disconnect_request->reply_message.reply_message[num];
|
||||
|
||||
reply_message->flag = 1;
|
||||
|
||||
strcpy(reply_message->reply_message.value,"Radius disconnect");
|
||||
|
||||
disconnect_request->reply_message.num++;
|
||||
|
||||
addr.addr.ipV4 = inet_addr("155.226.202.45");
|
||||
|
||||
radius_send_disconnect_request(0, 0, &pdu, &addr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_radius_cnf(WORD usr_pid, WORD pid, RADIUS_MSG *msg_pdu)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_radius_init()
|
||||
{
|
||||
int sap_index;
|
||||
RADIUS_SAP sap;
|
||||
RADIUS_NAS_INFORMATION nas;
|
||||
|
||||
strcpy(sap.name, "test_radius");
|
||||
|
||||
sap.radius_ind = test_radius_ind;
|
||||
sap.radius_cnf = test_radius_cnf;
|
||||
|
||||
radius_init();
|
||||
|
||||
sap_index = radius_bind(&sap);
|
||||
|
||||
nas.nas_ip = inet_addr("155.226.202.45");
|
||||
strcpy(nas.share_key, "topsecret");
|
||||
strcpy(nas.password, "test");
|
||||
|
||||
radius_set_nas_info(sap_index, 0, &nas);
|
||||
}
|
||||
|
||||
void test_radius(void)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
radius_timer();
|
||||
|
||||
usleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
7
plat/radius/ut/radius_unit_test.h
Normal file
7
plat/radius/ut/radius_unit_test.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _MGC_TEST_CASE_H
|
||||
#define _MGC_TEST_CASE_H
|
||||
|
||||
void test_radius_init();
|
||||
void test_radius();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user