r6209: started added code to support mailslot requests over UDP/138
[samba.git] / source / librpc / idl / nbt.idl
1 #include "idl_types.h"
2
3 /*
4    IDL structures for NBT operations
5
6    NBT is not traditionally encoded using IDL/NDR. This is a bit of an
7    experiment, and I may well switch us back to a more traditional
8    encoding if it doesn't work out
9 */
10
11 interface nbt
12 {
13         const int NBT_NAME_SERVICE_PORT  = 137;
14         const int NBT_DGRAM_SERVICE_PORT = 138;
15
16         typedef [bitmap16bit] bitmap {
17                 NBT_RCODE                   = 0x000F,
18                 NBT_FLAG_BROADCAST          = 0x0010,
19                 NBT_FLAG_RECURSION_AVAIL    = 0x0080,
20                 NBT_FLAG_RECURSION_DESIRED  = 0x0100,
21                 NBT_FLAG_TRUNCATION         = 0x0200,
22                 NBT_FLAG_AUTHORITIVE        = 0x0400,
23                 NBT_OPCODE                  = 0x7800,
24                 NBT_FLAG_REPLY              = 0x8000
25         } nbt_operation;
26
27         /* the opcodes are in the operation field, masked with
28            NBT_OPCODE */
29         typedef enum {
30                 NBT_OPCODE_QUERY          =  (0x0<<11),
31                 NBT_OPCODE_REGISTER       =  (0x5<<11),
32                 NBT_OPCODE_RELEASE        =  (0x6<<11),
33                 NBT_OPCODE_WACK           =  (0x7<<11),
34                 NBT_OPCODE_REFRESH        =  (0x8<<11),
35                 NBT_OPCODE_REFRESH2       =  (0x9<<11),
36                 NBT_OPCODE_MULTI_HOME_REG =  (0xf<<11)
37         } nbt_opcode;
38
39         /* rcode values */
40         typedef enum {
41                 NBT_RCODE_OK  = 0x0,
42                 NBT_RCODE_FMT = 0x1,
43                 NBT_RCODE_SVR = 0x2,
44                 NBT_RCODE_NAM = 0x3,
45                 NBT_RCODE_IMP = 0x4,
46                 NBT_RCODE_RFS = 0x5,
47                 NBT_RCODE_ACT = 0x6,
48                 NBT_RCODE_CFT = 0x7
49         } nbt_rcode;
50
51         /* we support any 8bit name type, but by defining the common
52            ones here we get better debug displays */
53         typedef [enum8bit] enum {
54                 NBT_NAME_CLIENT   = 0x00,
55                 NBT_NAME_MS       = 0x01,
56                 NBT_NAME_USER     = 0x03,
57                 NBT_NAME_SERVER   = 0x20,
58                 NBT_NAME_PDC      = 0x1B,
59                 NBT_NAME_LOGON    = 0x1C,
60                 NBT_NAME_MASTER   = 0x1D,
61                 NBT_NAME_BROWSER  = 0x1E
62         } nbt_name_type;
63
64         /* the ndr parser for nbt_name is separately defined in
65            nbtname.c */
66         typedef [nopull,nopush] struct {
67                 string        name;
68                 string        scope;
69                 nbt_name_type type;
70         } nbt_name;
71
72         typedef [enum16bit] enum {
73                 NBT_QCLASS_IP = 0x01
74         } nbt_qclass;
75
76         typedef [enum16bit] enum {
77                 NBT_QTYPE_ADDRESS     = 0x0001,
78                 NBT_QTYPE_NAMESERVICE = 0x0002,
79                 NBT_QTYPE_NULL        = 0x000A,
80                 NBT_QTYPE_NETBIOS     = 0x0020,
81                 NBT_QTYPE_STATUS      = 0x0021
82         } nbt_qtype;
83
84         typedef struct {
85                 nbt_name   name;
86                 nbt_qtype  question_type;
87                 nbt_qclass question_class;
88         } nbt_name_question;
89
90         /* these are the possible values of the NBT_NM_OWNER_TYPE
91            field */
92         typedef enum {
93                 NBT_NODE_B = 0x0000,
94                 NBT_NODE_P = 0x2000,
95                 NBT_NODE_M = 0x4000,
96                 NBT_NODE_H = 0x6000
97         } nbt_node_type;
98
99         typedef [bitmap16bit] bitmap {
100                 NBT_NM_PERMANENT        = 0x0200,
101                 NBT_NM_ACTIVE           = 0x0400,
102                 NBT_NM_CONFLICT         = 0x0800,
103                 NBT_NM_DEREGISTER       = 0x1000,
104                 NBT_NM_OWNER_TYPE       = 0x6000,
105                 NBT_NM_GROUP            = 0x8000
106         } nb_flags;
107
108         typedef struct {
109                 nb_flags nb_flags;
110                 ipv4address ipaddr;
111         } nbt_rdata_address;
112
113         typedef struct {
114                 uint16 length;
115                 nbt_rdata_address addresses[length/6];
116         } nbt_rdata_netbios;
117
118         typedef struct {
119                 uint8 unit_id[6];
120                 uint8 jumpers;
121                 uint8 test_result;
122                 uint16 version_number;
123                 uint16 period_of_statistics;
124                 uint16 number_of_crcs;
125                 uint16 number_alignment_errors;
126                 uint16 number_of_collisions;
127                 uint16 number_send_aborts;
128                 uint32 number_good_sends;
129                 uint32 number_good_receives;
130                 uint16 number_retransmits;
131                 uint16 number_no_resource_conditions;
132                 uint16 number_free_command_blocks;
133                 uint16 total_number_command_blocks;
134                 uint16 max_total_number_command_blocks;
135                 uint16 number_pending_sessions;
136                 uint16 max_number_pending_sessions;
137                 uint16 max_total_sessions_possible;
138                 uint16 session_data_packet_size;
139         } nbt_statistics;
140
141         typedef struct {
142                 astring15 name;
143                 nbt_name_type type;
144                 nb_flags  nb_flags;
145         } nbt_status_name;
146
147         typedef struct {
148                 [value(r->num_names * 18 + 47)] uint16 length;
149                 uint8 num_names;
150                 nbt_status_name names[num_names];
151                 nbt_statistics  statistics;
152         } nbt_rdata_status;
153
154         typedef struct {
155                 uint16 length;
156                 uint8  data[length];
157         } nbt_rdata_data;
158
159         typedef [nodiscriminant] union {
160                 [case(NBT_QTYPE_NETBIOS)] nbt_rdata_netbios netbios;
161                 [case(NBT_QTYPE_STATUS)]  nbt_rdata_status status;
162                 [default]                 nbt_rdata_data   data;
163         } nbt_rdata;
164
165         typedef [flag(LIBNDR_PRINT_ARRAY_HEX)] struct {
166                 nbt_name   name;
167                 nbt_qtype  rr_type;
168                 nbt_qclass rr_class;
169                 uint32     ttl;
170                 [switch_is(rr_type)] nbt_rdata rdata;
171         } nbt_res_rec;
172
173         typedef [flag(NDR_NOALIGN|NDR_BIG_ENDIAN|NDR_PAHEX),public] struct {
174                 uint16            name_trn_id;
175                 nbt_operation     operation;
176                 uint16            qdcount;
177                 uint16            ancount;
178                 uint16            nscount;
179                 uint16            arcount;
180                 nbt_name_question questions[qdcount];
181                 nbt_res_rec       answers[ancount];
182                 nbt_res_rec       nsrecs[nscount];
183                 nbt_res_rec       additional[arcount];
184                 [flag(NDR_REMAINING)] DATA_BLOB padding;
185         } nbt_name_packet;
186
187
188         /*
189           NBT DGRAM packets (UDP/138)
190         */
191
192         typedef [enum8bit] enum {
193                 DGRAM_DIRECT_UNIQUE  = 0x10,
194                 DGRAM_DIRECT_GROUP   = 0x11,
195                 DGRAM_BCAST          = 0x12,
196                 DGRAM_ERROR          = 0x13,
197                 DGRAM_QUERY          = 0x14,
198                 DGRAM_QUERY_POSITIVE = 0x15,
199                 DGRAM_QUERY_NEGATIVE = 0x16
200         } dgram_msg_type;
201
202         typedef [bitmap8bit] bitmap {
203                 DGRAM_FLAG_MORE         = 0x80,
204                 DGRAM_FLAG_FIRST        = 0x40,
205                 DGRAM_FLAG_NODE_TYPE    = 0x30
206         } dgram_flags;
207
208         typedef [enum8bit] enum {
209                 DGRAM_NODE_B    = 0x00,
210                 DGRAM_NODE_P    = 0x10,
211                 DGRAM_NODE_M    = 0x20,
212                 DGRAM_NODE_NBDD = 0x30
213         } dgram_node_type;
214
215         /* a dgram_message is the main dgram body in general use */
216
217         /* the most common datagram type is a SMB_TRANSACTION
218            operation, where a SMB packet is used in the data section
219            of a dgram_message to hold a trans request, which in turn
220            holds a small command structure. It's a very strange beast
221            indeed. To make the code cleaner we define a basic SMB
222            packet in IDL here. This is not a general purpose SMB
223            packet, and won't be used in the core SMB client/server
224            code, but it does make working with these types of dgrams
225            easier */
226
227         typedef [enum8bit] enum {
228                 SMB_TRANSACTION = 0x25
229         } smb_command;
230
231         typedef struct {
232                 [range(17,17),value(17)] uint8 wct;
233                 uint16                      total_param_count;
234                 uint16                      total_data_count;
235                 uint16                      max_param_count;
236                 uint16                      max_data_count;
237                 uint8                       max_setup_count;
238                 uint8                       pad;
239                 uint16                      trans_flags;
240                 uint32                      timeout;
241                 uint16                      reserved;
242                 uint16                      param_count;
243                 uint16                      param_offset;
244                 uint16                      data_count;
245                 uint16                      data_offset;
246                 [range(3,3),value(3)] uint8 setup_count;
247                 uint8                       pad2;
248                 uint16                      opcode;
249                 uint16                      priority;
250                 uint16                      class;
251                 [value(strlen(r->mailslot_name)+1+r->data.length)] 
252                       uint16                byte_count;
253                 astring                     mailslot_name;
254                 [flag(NDR_REMAINING)] DATA_BLOB data;
255         } smb_trans_body;
256
257         typedef [nodiscriminant] union {
258                 [case(SMB_TRANSACTION)] smb_trans_body trans;
259         } smb_body;
260
261
262         typedef [flag(NDR_NOALIGN|NDR_LITTLE_ENDIAN|NDR_PAHEX),public] struct {
263                 smb_command                smb_command;
264                 uint8                      err_class;
265                 uint8                      pad;
266                 uint16                     err_code;
267                 uint8                      flags;
268                 uint16                     flags2;
269                 uint16                     pid_high;
270                 uint8                      signature[8];
271                 uint16                     reserved;
272                 uint16                     tid;
273                 uint16                     pid;
274                 uint16                     vuid;
275                 uint16                     mid;
276                 [switch_is(smb_command)]   smb_body body;
277         } dgram_smb_packet;
278
279         typedef [v1_enum] enum {
280                 DGRAM_SMB = 0xff534d42 /* 0xffSMB */
281         } dgram_body_type;
282
283         typedef [nodiscriminant] union {
284                 [case(DGRAM_SMB)] dgram_smb_packet smb;
285         } dgram_message_body;
286
287         typedef struct {
288                 uint16          length;
289                 uint16          offset;
290                 nbt_name        source_name;
291                 nbt_name        dest_name;
292                 dgram_body_type dgram_body_type;
293                 [switch_is(dgram_body_type)] dgram_message_body body;
294         } dgram_message;
295
296         typedef [enum8bit] enum {
297                 DGRAM_ERROR_NAME_NOT_PRESENT = 0x82,
298                 DGRAM_ERROR_INVALID_SOURCE   = 0x83,
299                 DGRAM_ERROR_INVALID_DEST     = 0x84
300         } dgram_err_code;
301
302         typedef [nodiscriminant] union {
303                 [case(DGRAM_DIRECT_UNIQUE)]   dgram_message  msg;
304                 [case(DGRAM_DIRECT_GROUP)]    dgram_message  msg;
305                 [case(DGRAM_BCAST)]           dgram_message  msg;
306                 [case(DGRAM_ERROR)]           dgram_err_code error;
307                 [case(DGRAM_QUERY)]           nbt_name       dest_name;
308                 [case(DGRAM_QUERY_POSITIVE)]  nbt_name       dest_name;
309                 [case(DGRAM_QUERY_NEGATIVE)]  nbt_name       dest_name;
310         } dgram_data;
311
312         typedef [flag(NDR_NOALIGN|NDR_BIG_ENDIAN|NDR_PAHEX),public] struct {
313                 dgram_msg_type msg_type;
314                 dgram_flags    flags;
315                 uint16         dgram_id;
316                 ipv4address    source;
317                 uint16         src_port;
318                 [switch_is(msg_type)] dgram_data data;
319         } nbt_dgram_packet;
320 }