1 /* Copyright (c) 2007-2008, UNINETT AS */
2 /* Copyright (c) 2015, NORDUnet A/S */
3 /* See LICENSE for licensing information. */
4 
5 #ifndef _RADMSG_H
6 #define _RADMSG_H
7 
8 #include "tlv11.h"
9 
10 #define RAD_Max_Attr_Value_Length 253
11 
12 #define RAD_Access_Request 1
13 #define RAD_Access_Accept 2
14 #define RAD_Access_Reject 3
15 #define RAD_Accounting_Request 4
16 #define RAD_Accounting_Response 5
17 #define RAD_Access_Challenge 11
18 #define RAD_Status_Server 12
19 #define RAD_Status_Client 13
20 
21 #define RAD_Attr_User_Name 1
22 #define RAD_Attr_User_Password 2
23 #define RAD_Attr_CHAP_Password 3
24 #define RAD_Attr_Reply_Message 18
25 #define RAD_Attr_Vendor_Specific 26
26 #define RAD_Attr_Calling_Station_Id 31
27 #define RAD_Attr_Proxy_State 33
28 #define RAD_Attr_CHAP_Challenge 60
29 #define RAD_Attr_Tunnel_Password 69
30 #define RAD_Attr_Message_Authenticator 80
31 
32 #define RAD_VS_ATTR_MS_MPPE_Send_Key 16
33 #define RAD_VS_ATTR_MS_MPPE_Recv_Key 17
34 
35 struct radmsg {
36     uint8_t code;
37     uint8_t id;
38     uint8_t auth[20];
39     struct list *attrs; /*struct tlv*/
40 };
41 
42 #define ATTRTYPE(x) ((x)[0])
43 #define ATTRLEN(x) ((x)[1])
44 #define ATTRVAL(x) ((x) + 2)
45 #define ATTRVALLEN(x) ((x)[1] - 2)
46 
47 void radmsg_free(struct radmsg *);
48 struct radmsg *radmsg_init(uint8_t, uint8_t, uint8_t *);
49 int radmsg_add(struct radmsg *, struct tlv *);
50 struct tlv *radmsg_gettype(struct radmsg *, uint8_t);
51 struct list *radmsg_getalltype(const struct radmsg *msg, uint8_t type);
52 int radmsg_copy_attrs(struct radmsg *dst,
53                       const struct radmsg *src,
54                       uint8_t type);
55 uint8_t *tlv2buf(uint8_t *p, const struct tlv *tlv);
56 uint8_t *radmsg2buf(struct radmsg *msg, uint8_t *, int);
57 struct radmsg *buf2radmsg(uint8_t *, uint8_t *, int, uint8_t *);
58 uint8_t attrname2val(char *attrname);
59 int vattrname2val(char *attrname, uint32_t *vendor, uint32_t *type);
60 int attrvalidate(unsigned char *attrs, int length);
61 struct tlv *makevendortlv(uint32_t vendor, struct tlv *attr);
62 int resizeattr(struct tlv *attr, uint8_t newlen);
63 
64 #endif /*_RADMSG_H*/
65 
66 /* Local Variables: */
67 /* c-file-style: "stroustrup" */
68 /* End: */
69