1f7d24e3fSHanoh Haim## This file is part of Scapy
2f7d24e3fSHanoh Haim## See http://www.secdev.org/projects/scapy for more informations
3f7d24e3fSHanoh Haim## Copyright (C) Philippe Biondi <phil@secdev.org>
4f7d24e3fSHanoh Haim## This program is published under a GPLv2 license
5f7d24e3fSHanoh Haim
6f7d24e3fSHanoh Haim"""
7f7d24e3fSHanoh HaimRADIUS (Remote Authentication Dial In User Service)
8f7d24e3fSHanoh Haim"""
9f7d24e3fSHanoh Haim
10f7d24e3fSHanoh Haimimport struct
11f7d24e3fSHanoh Haimfrom scapy.packet import *
12f7d24e3fSHanoh Haimfrom scapy.fields import *
13f7d24e3fSHanoh Haim
14f7d24e3fSHanoh Haimclass Radius(Packet):
15f7d24e3fSHanoh Haim    name = "Radius"
16f7d24e3fSHanoh Haim    fields_desc = [ ByteEnumField("code", 1, {1: "Access-Request",
17f7d24e3fSHanoh Haim                                              2: "Access-Accept",
18f7d24e3fSHanoh Haim                                              3: "Access-Reject",
19f7d24e3fSHanoh Haim                                              4: "Accounting-Request",
20f7d24e3fSHanoh Haim                                              5: "Accounting-Accept",
21f7d24e3fSHanoh Haim                                              6: "Accounting-Status",
22f7d24e3fSHanoh Haim                                              7: "Password-Request",
23f7d24e3fSHanoh Haim                                              8: "Password-Ack",
24f7d24e3fSHanoh Haim                                              9: "Password-Reject",
25f7d24e3fSHanoh Haim                                              10: "Accounting-Message",
26f7d24e3fSHanoh Haim                                              11: "Access-Challenge",
27f7d24e3fSHanoh Haim                                              12: "Status-Server",
28f7d24e3fSHanoh Haim                                              13: "Status-Client",
29f7d24e3fSHanoh Haim                                              21: "Resource-Free-Request",
30f7d24e3fSHanoh Haim                                              22: "Resource-Free-Response",
31f7d24e3fSHanoh Haim                                              23: "Resource-Query-Request",
32f7d24e3fSHanoh Haim                                              24: "Resource-Query-Response",
33f7d24e3fSHanoh Haim                                              25: "Alternate-Resource-Reclaim-Request",
34f7d24e3fSHanoh Haim                                              26: "NAS-Reboot-Request",
35f7d24e3fSHanoh Haim                                              27: "NAS-Reboot-Response",
36f7d24e3fSHanoh Haim                                              29: "Next-Passcode",
37f7d24e3fSHanoh Haim                                              30: "New-Pin",
38f7d24e3fSHanoh Haim                                              31: "Terminate-Session",
39f7d24e3fSHanoh Haim                                              32: "Password-Expired",
40f7d24e3fSHanoh Haim                                              33: "Event-Request",
41f7d24e3fSHanoh Haim                                              34: "Event-Response",
42f7d24e3fSHanoh Haim                                              40: "Disconnect-Request",
43f7d24e3fSHanoh Haim                                              41: "Disconnect-ACK",
44f7d24e3fSHanoh Haim                                              42: "Disconnect-NAK",
45f7d24e3fSHanoh Haim                                              43: "CoA-Request",
46f7d24e3fSHanoh Haim                                              44: "CoA-ACK",
47f7d24e3fSHanoh Haim                                              45: "CoA-NAK",
48f7d24e3fSHanoh Haim                                              50: "IP-Address-Allocate",
49f7d24e3fSHanoh Haim                                              51: "IP-Address-Release",
50f7d24e3fSHanoh Haim                                              253: "Experimental-use",
51f7d24e3fSHanoh Haim                                              254: "Reserved",
52f7d24e3fSHanoh Haim                                              255: "Reserved"} ),
53f7d24e3fSHanoh Haim                    ByteField("id", 0),
54f7d24e3fSHanoh Haim                    ShortField("len", None),
55f7d24e3fSHanoh Haim                    StrFixedLenField("authenticator","",16) ]
56f7d24e3fSHanoh Haim    def post_build(self, p, pay):
57f7d24e3fSHanoh Haim        p += pay
58f7d24e3fSHanoh Haim        l = self.len
59f7d24e3fSHanoh Haim        if l is None:
60f7d24e3fSHanoh Haim            l = len(p)
61f7d24e3fSHanoh Haim            p = p[:2]+struct.pack("!H",l)+p[4:]
62f7d24e3fSHanoh Haim        return p
63f7d24e3fSHanoh Haim
64f7d24e3fSHanoh Haim
65f7d24e3fSHanoh Haim
66