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 
21 #ifndef UHCP_H
22 #define UHCP_H
23 
24 #include <stdint.h>
25 #include <stddef.h>
26 #include <arpa/inet.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
33 #define UHCP_MAGIC (0x55484350) /* "UHCP" in hex */
34 
36 #define UHCP_VER (0)
37 
39 #define UHCP_PORT (12345U)
40 
42 #define UHCP_PORT_STR "12345"
43 
45 typedef enum {
48 } uhcp_type_t;
49 
53 typedef struct __attribute__((packed)) {
54  uint32_t uhcp_magic;
55  uint8_t ver_type;
57 } uhcp_hdr_t;
58 
64 typedef struct __attribute__((packed)) {
66  uint8_t prefix_len;
67 } uhcp_req_t;
68 
74 typedef struct __attribute__((packed)) {
76  uint8_t prefix_len;
78  uint8_t prefix[];
79 } uhcp_push_t;
80 
82 typedef unsigned uhcp_iface_t;
83 
96 void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface);
97 
111 void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
112 
126 void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
127 
145 void uhcp_handle_prefix(uint8_t *prefix, uint8_t prefix_len, uint16_t lifetime, uint8_t *src, uhcp_iface_t iface);
146 
155 static inline void uhcp_hdr_set(uhcp_hdr_t *hdr, uhcp_type_t type)
156 {
157  hdr->uhcp_magic = htonl(UHCP_MAGIC);
158  hdr->ver_type = (UHCP_VER << 4) | (type & 0xF);
159 }
160 
172 int udp_sendto(uint8_t *buf, size_t len, uint8_t *dst, uint16_t dst_port, uhcp_iface_t dst_iface);
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif /* UHCP_H */
179 
struct for push packets
Definition: uhcp.h:74
UHCP packet header struct.
Definition: uhcp.h:53
#define UHCP_MAGIC
UHCP magic number.
Definition: uhcp.h:33
static uint32_t htonl(uint32_t v)
Convert from host byte order to network byte order, 32 bit.
Definition: byteorder.h:393
packet is a push / answer packet
Definition: uhcp.h:47
uhcp_hdr_t hdr
member holding parent type
Definition: uhcp.h:65
uint8_t prefix_len
contains the requested prefix length
Definition: uhcp.h:66
#define UHCP_VER
UHCP version of this header.
Definition: uhcp.h:36
static void uhcp_hdr_set(uhcp_hdr_t *hdr, uhcp_type_t type)
function to set constant values in UHCP header
Definition: uhcp.h:155
void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UDP packet
unsigned uhcp_iface_t
typedef for interface handle
Definition: uhcp.h:82
struct for request packets
Definition: uhcp.h:64
uhcp_hdr_t hdr
member holding parent type
Definition: uhcp.h:75
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)
void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UHCP request packet
uhcp_type_t
Enum containing possible UHCP packet types.
Definition: uhcp.h:45
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.
Definitions for internet operations.
void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UHCP push packet
uint8_t prefix_len
contains the prefix length of assigned prefix
Definition: uhcp.h:76
uint8_t ver_type
four bits version number, four bits packet type (see uchp_type_t)
Definition: uhcp.h:55
packet is a request packet
Definition: uhcp.h:46
uint32_t uhcp_magic
always contains UHCP in hex
Definition: uhcp.h:54