Main Page | Class List | File List | Class Members

RadiusPacket Class Reference

Implementation of RADIUS packet. More...

#include <RadiusPacket.h>

List of all members.

Public Member Functions

 RadiusPacket (unsigned char p_code, RadiusClientStack &p_stack)
 Constructor.
 RadiusPacket (unsigned char p_code, RadiusPacket &p_request)
 Constructor.
 RadiusPacket (unsigned char p_code)
 Constructor.
 RadiusPacket (const RadiusPacket &p_packet)
 Copy constructor.
 ~RadiusPacket ()
 Destructor.
unsigned char getCode (void)
 Get packet code.
const char * getCodeDescription (void)
 Get packet code description.
uint16_t getLength (void)
 Get packet length.
unsigned char getID (void)
 Get packet identifier.
void setID (unsigned char p_id)
 Set packet identifier.
void randomID ()
 Set random packet identifier.
RadiusSecretgetSecret (void)
 Get secret key used for packet encoding.
void setSecret (RadiusSecret *p_secret)
 Set secret key used for packet encoding.
const unsigned char * getAuthenticator (void)
 Get packet authenticator.
void setAuthenticator (const unsigned char *p_auth)
 Set packet authenticator.
void dump ()
 Dump radius packet in readable text format to the STDOUT.
int getFirstAttribute (RadiusAttribute &p_attr)
 Get first attribute in the packet.
int getNextAttribute (RadiusAttribute &p_attr)
 Get next attribute in the packet.
int findAttribute (unsigned char p_attrType, RadiusAttribute &p_attr)
 Find specific attribute in the packet.
int addAttribute (unsigned char p_attrType, RadiusAttribute &p_attr)
 Add new attribute to the packet.
unsigned char * getRawData (void)
 Get raw packet data.
int adjustLength (uint16_t p_length)
 Adjust packet's length.
void responseAuthenticator (RadiusSecret *p_secret=NULL)
 Generate authenticator for response packet.
void accountingRequestAuthenticator (RadiusSecret *p_secret=NULL)
 Generate authenticator for accounting request packet.
bool verifyResponse (RadiusPacket &p_packet)
 Verify RADIUS response.

Private Member Functions

void init (unsigned char p_code)
 Init packet.
void randomAuthenticator (void)
 Generate pseudo-random authenticator.
void setCode (unsigned char p_code)
 Set packet's code.
void setLength (uint16_t p_length)
 Set packet's length.

Private Attributes

unsigned char m_data [D_RAW_DATA_LENGTH]
 Raw packet data.
RadiusSecretm_secret
 RADIUS secret associated with this packet.


Detailed Description

Implementation of RADIUS packet.

RadiusPacket class is responsible for holding data transferred to/from the network and providing simple interface to build new outgoing RADIUS packet and to parse incoming packet.


Constructor & Destructor Documentation

RadiusPacket::RadiusPacket unsigned char  p_code,
RadiusClientStack p_stack
 

Constructor.

This constructor should be used for constructing RADIUS requests (i.e. by RADIUS client application). It automatically generates random Authenticator, however application may override this later on by calling setAuthenticator() method.

Parameters:
[in] p_code - packet code

RadiusPacket::RadiusPacket unsigned char  p_code,
RadiusPacket p_request
 

Constructor.

This constructor should be used for constructing RADIUS responses (i.e. by RADIUS server application). Original RADIUS request should be passed as parameter to it.

Parameters:
[in] p_code - packet code
[in] p_request - original RADIUS request packet

RadiusPacket::RadiusPacket unsigned char  p_code  ) 
 

Constructor.

This constructor should be used for constructing RADIUS requests. It automatically generates random Authenticator, however application may override this later on by calling setAuthenticator() method.

Most applications should use the former constructors instead of this one. If for any reason you decide to use this constructor, make sure to update packet's identifier (by default packet will have zero ID).

Parameters:
[in] p_code - packet code


Member Function Documentation

unsigned char RadiusPacket::getCode void   ) 
 

Get packet code.

Returns:
packet code

uint16_t RadiusPacket::getLength void   ) 
 

Get packet length.

Returns:
packet length

unsigned char RadiusPacket::getID void   ) 
 

Get packet identifier.

Returns:
packet identifier

void RadiusPacket::setID unsigned char  p_id  ) 
 

Set packet identifier.

Parameters:
[in] p_id - packet identifier

RadiusSecret * RadiusPacket::getSecret void   ) 
 

Get secret key used for packet encoding.

Returns:
secret key

void RadiusPacket::setSecret RadiusSecret p_secret  ) 
 

Set secret key used for packet encoding.

Parameters:
[in] p_secret - secret key

int RadiusPacket::getFirstAttribute RadiusAttribute p_attr  ) 
 

Get first attribute in the packet.

Updates p_attr to point at the first attribute in the packet. If packet has no attributes "invalid" attribute is returned.

Typical code that goes over all attributes in the packet looks as follows:

     RadiusAttribute l_attr;
     for (packet->getFirstAttribute(l_attr); 
          l_attr.isValid(); 
          packet->getNextAttribute(l_attr))
     {
         // do something with the attribute
     }
Application can analyze return code or use isValid() method of RadiusAttribute to verify validity of the returned attribute.

Parameters:
[out] p_attr - first attribute in the packet
Returns:
RC_SUCCESS or RC_FAIL

int RadiusPacket::getNextAttribute RadiusAttribute p_attr  ) 
 

Get next attribute in the packet.

Updates p_attr to point at the next attribute in the packet after the one that it was pointing at prior to calling this function. If no more attributes are found "invalid" attribute is returned.

Application can analyze return code or use isValid() method of RadiusAttribute to verify validity of the returned attribute.

Parameters:
[in,out] p_attr - input - current attribute; output - next attribute
Returns:
RC_SUCCESS or RC_FAIL

int RadiusPacket::findAttribute unsigned char  p_attrType,
RadiusAttribute p_attr
 

Find specific attribute in the packet.

Updates p_attr to point at the first attribute of specified type in the packet. If attribute is not found "invalid" attribute is returned. If more than one instance of the same attribute exist in the packet, application should use getNextAttribute() interface to retrieve them.

Application can analyze return code or use isValid() method of RadiusAttribute to verify validity of the returned attribute.

Parameters:
[in,out] p_attr - input - current attribute; output - next attribute
Returns:
RC_SUCCESS or RC_FAIL

int RadiusPacket::addAttribute unsigned char  p_attrType,
RadiusAttribute p_attr
 

Add new attribute to the packet.

Updates p_attr to point at the free space in the packet. Returns RadiusAttribute structure should be used by application in order to set attribute's value. If packet is full, "invalid" attribute is returned.

Actual attribute's data is not encoded into the packet until proper attribute's set() method is called. So if application calls addAttribute() and then suddenly changes it's mind, it's perfectly OK to simply call addAttribute() again or send the packet "as is".

Application can analyze return code or use isValid() method of RadiusAttribute to verify validity of the returned attribute.

Parameters:
[in] p_attrType - attribute type
[out] p_attr - reference to the added attribute
Returns:
RC_SUCCESS or RC_FAIL

int RadiusPacket::adjustLength uint16_t  p_length  ) 
 

Adjust packet's length.

Adjust (increase) packet's length by specified number of bytes. If packet has not enough space to accomodate requested data, RC_FAIL is returned.

Parameters:
[in] p_length - how many bytes should be added to the packet
Returns:
RC_SUCCESS or RC_FAIL

void RadiusPacket::responseAuthenticator RadiusSecret p_secret = NULL  ) 
 

Generate authenticator for response packet.

Packet's authenticator should be initially set to the request's authenticator. This method should be called once only - prior to sending the packet over the network. Usually RadiusServer does the job, so user application doesn't have to bother.

Parameters:
[in] p_secret - secret key (if NULL, stack's secret key is taken)

void RadiusPacket::accountingRequestAuthenticator RadiusSecret p_secret = NULL  ) 
 

Generate authenticator for accounting request packet.

Packet's attributes should be ready before calling This method should be called once only - prior to sending the packet over the network. Usually RadiusClientStack does the job, so user application doesn't have to bother.

Parameters:
[in] p_secret - secret key (if NULL, stack's secret key is taken)

void RadiusPacket::setCode unsigned char  p_code  )  [private]
 

Set packet's code.

Set packet's code. This method is intentionally put into the private section, since application should pass packet's code to RadiusPacket constructor.

Parameters:
[in] p_code - packet code

void RadiusPacket::setLength uint16_t  p_length  )  [private]
 

Set packet's length.

Set packet's length

Parameters:
[in] p_length - packet's length


The documentation for this class was generated from the following files:
Generated on Tue Aug 11 18:35:07 2009 for ace-radius by doxygen 1.3.7-20040704