1/*
2 * Copyright 2019, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
8 * See "LICENSE_GPLv2.txt" for details.
9 *
10 * @TAG(DATA61_GPL)
11 */
12
13#pragma once
14
15
16/*
17 * Reference only the necessary constants and functions to clients that are
18 * connected the PicoServer component.
19 *
20 * These constants and functions cover all the functionality that the
21 * PicoServer currently provides.
22 */
23#ifndef PICO_SOCK_EV_RD
24#define PICO_SOCK_EV_RD 1u
25#define PICO_SOCK_EV_WR 2u
26#define PICO_SOCK_EV_CONN 4u
27#define PICO_SOCK_EV_CLOSE 8u
28#define PICO_SOCK_EV_FIN 0x10u
29#define PICO_SOCK_EV_ERR 0x80u
30#define PICO_SHUT_RD   1
31#define PICO_SHUT_WR   2
32#define PICO_SHUT_RDWR 3
33#define PICO_IPV4_INADDR_ANY 0x00000000U
34#endif
35
36#define PICOSERVER_READ PICO_SOCK_EV_RD
37#define PICOSERVER_WRITE PICO_SOCK_EV_WR
38#define PICOSERVER_CONN PICO_SOCK_EV_CONN
39#define PICOSERVER_CLOSE PICO_SOCK_EV_CLOSE
40#define PICOSERVER_FIN PICO_SOCK_EV_FIN
41#define PICOSERVER_ERR PICO_SOCK_EV_ERR
42#define PICOSERVER_IP_AVAIL (PICO_SOCK_EV_ERR << 1)
43
44#define PICOSERVER_SHUT_RD PICO_SHUT_RD
45#define PICOSERVER_SHUT_WR PICO_SHUT_WR
46#define PICOSERVER_SHUT_RDWR PICO_SHUT_RDWR
47
48#define PICOSERVER_ANY_ADDR_IPV4 PICO_IPV4_INADDR_ANY
49
50/*
51 * These functions will convert an IP address in string form to a integer
52 * bitfield in network order format (1.2.3.4 -> 0x04030201), and vice versa.
53 *
54 * When converting a IPv4 address to a string, depending on the IP address, the
55 * length of the buffer will have to be at most 16 bytes long which includes
56 * the NULL byte at the end.
57 */
58int pico_ipv4_to_string(char *ipbuf, const uint32_t ip);
59int
60pico_string_to_ipv4(const char *ipstr, uint32_t *ip);
61