]> git.sur5r.net Git - ngadmin/blob - lib/src/protocol.h
Added the possibility to specify the command timeout.
[ngadmin] / lib / src / protocol.h
1
2 #ifndef DEF_PROTOCOL
3 #define DEF_PROTOCOL
4
5
6 #include <stdio.h>
7 #include <stdbool.h>
8 #include <string.h>
9 #include <arpa/inet.h>
10 #include <netinet/ether.h>
11
12 #include <ngadmin.h>
13 #include "list.h"
14 #include "lib.h"
15
16
17
18
19
20 struct ng_header {
21  char unk1; // always 1
22  char code;
23  char error;
24  char unk2; // always 0
25  unsigned short attr; // attribute code which caused error
26  char unk3[2]; // always 0
27  char client_mac[ETH_ALEN];
28  char switch_mac[ETH_ALEN];
29  unsigned int seqnum;
30  char proto_id[4]; // always "NSDP"
31  char unk4[4]; // always 0
32  char data[0];
33 } __attribute__((packed)) ;
34
35 struct attr_header {
36  unsigned short attr;
37  unsigned short size;
38  char data[0];
39 } __attribute__((packed)) ;
40
41
42 struct ng_packet {
43  union {
44   char *buffer;
45   struct ng_header *nh;
46  };
47  int maxlen;
48  struct attr_header *ah;
49 };
50
51
52 struct attr {
53  unsigned short attr;
54  unsigned short size;
55  void *data;
56 };
57
58
59
60 extern const unsigned short helloRequest[];
61
62 extern const struct ether_addr nullMac;
63
64
65
66 // 
67 int min (int a, int b);
68
69 // 
70 void initNgHeader (struct ng_header *nh, char code, const struct ether_addr *client_mac, const struct ether_addr *switch_mac, unsigned int seqnum);
71
72 // 
73 bool validateNgHeader (const struct ng_header *nh, char code, const struct ether_addr *client_mac, const struct ether_addr *switch_mac, unsigned int seqnum);
74
75 // 
76 void initNgPacket (struct ng_packet *np);
77
78 // 
79 void addPacketAttr (struct ng_packet *np, unsigned short attr, unsigned short size, void* data);
80
81 // 
82 void addPacketEmptyAttr (struct ng_packet *np, unsigned short attr);
83
84 // 
85 void addPacketByteAttr (struct ng_packet *np, unsigned short attr, char val);
86
87 // 
88 void addPacketShortAttr (struct ng_packet *np, unsigned short attr, short val);
89
90 // 
91 int getPacketTotalSize (const struct ng_packet *np);
92
93 // 
94 struct attr* newEmptyAttr (unsigned short attr);
95
96 // 
97 struct attr* newAttr (unsigned short attr, unsigned short size, void *data);
98
99 // 
100 struct attr* newByteAttr (unsigned short attr, unsigned char value);
101
102 // 
103 struct attr* newIntAttr (unsigned short attr, int value);
104
105 // 
106 void freeAttr (struct attr *at);
107
108 // 
109 void extractPacketAttributes (struct ng_packet *np, char *error, unsigned short *attr_error, List *attr);
110
111 // 
112 void extractSwitchAttributes (struct swi_attr *sa, const List *l);
113
114
115
116
117 #endif
118