nbns_common.h
Go to the documentation of this file.
1 /**
2  * @file nbns_common.h
3  * @brief Definitions common to NBNS client and NBNS responder
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2023 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.2.4
29  **/
30 
31 #ifndef _NBNS_COMMON_H
32 #define _NBNS_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "dns/dns_common.h"
37 
38 //Default resource record TTL (cache lifetime)
39 #ifndef NBNS_DEFAULT_RESOURCE_RECORD_TTL
40  #define NBNS_DEFAULT_RESOURCE_RECORD_TTL 120
41 #elif (NBNS_DEFAULT_RESOURCE_RECORD_TTL < 1)
42  #error NBNS_DEFAULT_RESOURCE_RECORD_TTL parameter is not valid
43 #endif
44 
45 //NBNS port number
46 #define NBNS_PORT 137
47 
48 //Macro definition
49 #define NBNS_ENCODE_H(c) ('A' + (((c) >> 4) & 0x0F))
50 #define NBNS_ENCODE_L(c) ('A' + ((c) & 0x0F))
51 
52 //C++ guard
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 
58 /**
59  * @brief NBNS flags
60  **/
61 
62 typedef enum
63 {
64  NBNS_ONT_BNODE = 0x0000,
65  NBNS_ONT_PNODE = 0x2000,
66  NBNS_ONT_MNODE = 0x4000,
67  NBNS_G_UNIQUE = 0x0000,
68  NBNS_G_GROUP = 0x8000
70 
71 
72 //CodeWarrior or Win32 compiler?
73 #if defined(__CWCC__) || defined(_WIN32)
74  #pragma pack(push, 1)
75 #endif
76 
77 
78 /**
79  * @brief NBNS message header
80  **/
81 
82 typedef __start_packed struct
83 {
84  uint16_t id; //0-1
85 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
86  uint8_t qr : 1; //2
87  uint8_t opcode : 4;
88  uint8_t aa : 1;
89  uint8_t tc : 1;
90  uint8_t rd : 1;
91  uint8_t ra : 1; //3
92  uint8_t z : 2;
93  uint8_t b : 1;
94  uint8_t rcode : 4;
95 #else
96  uint8_t rd : 1; //2
97  uint8_t tc : 1;
98  uint8_t aa : 1;
99  uint8_t opcode : 4;
100  uint8_t qr : 1;
101  uint8_t rcode : 4; //3
102  uint8_t b : 1;
103  uint8_t z : 2;
104  uint8_t ra : 1;
105 #endif
106  uint16_t qdcount; //4-5
107  uint16_t ancount; //6-7
108  uint16_t nscount; //8-9
109  uint16_t arcount; //10-11
110  uint8_t questions[]; //12
112 
113 
114 /**
115  * @brief NBNS address entry
116  **/
117 
118 typedef __start_packed struct
119 {
120  uint16_t flags;
123 
124 
125 //CodeWarrior or Win32 compiler?
126 #if defined(__CWCC__) || defined(_WIN32)
127  #pragma pack(pop)
128 #endif
129 
130 //NBNS related functions
131 error_t nbnsInit(NetInterface *interface);
132 
133 void nbnsProcessMessage(NetInterface *interface,
134  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
135  const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
136  void *param);
137 
138 size_t nbnsEncodeName(const char_t *src, uint8_t *dest);
139 
140 size_t nbnsParseName(const NbnsHeader *message,
141  size_t length, size_t pos, char_t *dest);
142 
144  size_t length, size_t pos, const char_t *name);
145 
146 //C++ guard
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif
uint8_t length
Definition: coap_common.h:193
bool_t nbnsCompareName(const NbnsHeader *message, size_t length, size_t pos, const char_t *name)
Compare NetBIOS names.
Definition: nbns_common.c:288
int bool_t
Definition: compiler_port.h:53
uint8_t b
Definition: nbns_common.h:102
uint16_t ancount
Definition: nbns_common.h:107
__start_packed struct @0 UdpHeader
UDP header.
uint8_t ra
Definition: nbns_common.h:104
error_t nbnsInit(NetInterface *interface)
NBNS related initialization.
Definition: nbns_common.c:55
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
char_t name[]
uint8_t z
Definition: nbns_common.h:103
uint8_t rcode
Definition: nbns_common.h:101
uint16_t id
Definition: nbns_common.h:84
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:268
size_t nbnsParseName(const NbnsHeader *message, size_t length, size_t pos, char_t *dest)
Decode a NetBIOS name.
Definition: nbns_common.c:204
IP pseudo header.
Definition: ip.h:98
__start_packed struct @0 NbnsHeader
NBNS message header.
error_t
Error codes.
Definition: error.h:43
uint16_t nscount
Definition: nbns_common.h:108
@ NBNS_ONT_PNODE
Definition: nbns_common.h:65
uint8_t tc
Definition: nbns_common.h:97
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
uint8_t questions[]
Definition: nbns_common.h:110
uint8_t qr
Definition: nbns_common.h:100
__start_packed struct _Ipv4Header __end_packed
uint8_t opcode
Definition: nbns_common.h:99
uint16_t arcount
Definition: nbns_common.h:109
__start_packed struct @1 NbnsAddrEntry
NBNS address entry.
@ NBNS_G_UNIQUE
Definition: nbns_common.h:67
char char_t
Definition: compiler_port.h:48
@ NBNS_G_GROUP
Definition: nbns_common.h:68
@ NBNS_ONT_MNODE
Definition: nbns_common.h:66
uint8_t message[]
Definition: chap.h:152
uint16_t qdcount
Definition: nbns_common.h:106
uint8_t rd
Definition: nbns_common.h:96
@ NBNS_ONT_BNODE
Definition: nbns_common.h:64
void nbnsProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
Process incoming NBNS message.
Definition: nbns_common.c:82
uint8_t aa
Definition: nbns_common.h:98
Ipv4Addr addr
Definition: nbns_common.h:121
TCP/IP stack core.
Common DNS routines.
size_t nbnsEncodeName(const char_t *src, uint8_t *dest)
Encode a NetBIOS name.
Definition: nbns_common.c:152
DnsFlags
NBNS flags.
Definition: nbns_common.h:63
uint16_t flags
Definition: nbns_common.h:120