uhcp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
30 #ifndef NET_UHCP_H
31 #define NET_UHCP_H
32 
33 #include <stdint.h>
34 #include <stddef.h>
35 #include <arpa/inet.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
42 #define UHCP_MAGIC (0x55484350) /* "UHCP" in hex */
43 
45 #define UHCP_VER (0)
46 
48 #define UHCP_PORT (12345U)
49 
51 #define UHCP_PORT_STR "12345"
52 
54 typedef enum {
57 } uhcp_type_t;
58 
62 typedef struct __attribute__((packed)) {
63  uint32_t uhcp_magic;
64  uint8_t ver_type;
66 } uhcp_hdr_t;
67 
73 typedef struct __attribute__((packed)) {
75  uint8_t prefix_len;
76 } uhcp_req_t;
77 
83 typedef struct __attribute__((packed)) {
85  uint8_t prefix_len;
87  uint8_t prefix[];
88 } uhcp_push_t;
89 
91 typedef unsigned uhcp_iface_t;
92 
105 void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface);
106 
120 void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
121 
135 void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
136 
155 void uhcp_handle_prefix(uint8_t *prefix, uint8_t prefix_len, uint16_t lifetime, uint8_t *src, uhcp_iface_t iface);
156 
165 static inline void uhcp_hdr_set(uhcp_hdr_t *hdr, uhcp_type_t type)
166 {
167  hdr->uhcp_magic = htonl(UHCP_MAGIC);
168  hdr->ver_type = (UHCP_VER << 4) | (type & 0xF);
169 }
170 
182 int udp_sendto(uint8_t *buf, size_t len, uint8_t *dst, uint16_t dst_port, uhcp_iface_t dst_iface);
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif /* NET_UHCP_H */
189 
inet.h
Definitions for internet operations.
uhcp_push_t
struct for push packets
Definition: uhcp.h:83
uhcp_handle_udp
void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UDP packet
uhcp_push_t::prefix_len
uint8_t prefix_len
contains the prefix length of assigned prefix
Definition: uhcp.h:85
uhcp_iface_t
unsigned uhcp_iface_t
typedef for interface handle
Definition: uhcp.h:91
UHCP_MAGIC
#define UHCP_MAGIC
UHCP magic number.
Definition: uhcp.h:42
uhcp_handle_req
void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UHCP request packet
uhcp_hdr_set
static void uhcp_hdr_set(uhcp_hdr_t *hdr, uhcp_type_t type)
function to set constant values in UHCP header
Definition: uhcp.h:165
uhcp_hdr_t
UHCP packet header struct.
Definition: uhcp.h:62
uhcp_req_t::hdr
uhcp_hdr_t hdr
member holding parent type
Definition: uhcp.h:74
uhcp_type_t
uhcp_type_t
Enum containing possible UHCP packet types.
Definition: uhcp.h:54
UHCP_VER
#define UHCP_VER
UHCP version of this header.
Definition: uhcp.h:45
uhcp_handle_prefix
void uhcp_handle_prefix(uint8_t *prefix, uint8_t prefix_len, uint16_t lifetime, uint8_t *src, uhcp_iface_t iface)
handle incoming prefix (as parsed from push packet)
UHCP_REQ
@ UHCP_REQ
packet is a request packet
Definition: uhcp.h:55
uhcp_req_t::prefix_len
uint8_t prefix_len
contains the requested prefix length
Definition: uhcp.h:75
htonl
static uint32_t htonl(uint32_t v)
Convert from host byte order to network byte order, 32 bit.
Definition: byteorder.h:478
uhcp_hdr_t::ver_type
uint8_t ver_type
four bits version number, four bits packet type (see uchp_type_t)
Definition: uhcp.h:64
udp_sendto
int udp_sendto(uint8_t *buf, size_t len, uint8_t *dst, uint16_t dst_port, uhcp_iface_t dst_iface)
UDP send function used by UHCP client / server.
UHCP_PUSH
@ UHCP_PUSH
packet is a push / answer packet
Definition: uhcp.h:56
uhcp_hdr_t::uhcp_magic
uint32_t uhcp_magic
always contains UHCP in hex
Definition: uhcp.h:63
uhcp_push_t::hdr
uhcp_hdr_t hdr
member holding parent type
Definition: uhcp.h:84
uhcp_handle_push
void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UHCP push packet
uhcp_req_t
struct for request packets
Definition: uhcp.h:73