1 /** @file
2  * @brief NET_MGMT socket definitions.
3  *
4  * Definitions for NET_MGMT socket support.
5  */
6 
7 /*
8  * Copyright (c) 2019 Intel Corporation
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #ifndef ZEPHYR_INCLUDE_NET_SOCKET_NET_MGMT_H_
14 #define ZEPHYR_INCLUDE_NET_SOCKET_NET_MGMT_H_
15 
16 #include <zephyr/types.h>
17 #include <zephyr/net/net_ip.h>
18 #include <zephyr/net/net_if.h>
19 #include <zephyr/net/net_mgmt.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @brief Socket NET_MGMT library
27  * @defgroup socket_net_mgmt Socket NET_MGMT library
28  * @since 2.0
29  * @version 0.1.0
30  * @ingroup networking
31  * @{
32  */
33 
34 /** @cond INTERNAL_HIDDEN */
35 
36 /* Protocols of the protocol family PF_NET_MGMT */
37 #define NET_MGMT_EVENT_PROTO 0x01
38 
39 /* Socket NET_MGMT options */
40 #define SOL_NET_MGMT_BASE 100
41 #define SOL_NET_MGMT_RAW (SOL_NET_MGMT_BASE + 1)
42 
43 /** @endcond */
44 
45 /**
46  * struct sockaddr_nm - The sockaddr structure for NET_MGMT sockets
47  *
48  * Similar concepts are used as in Linux AF_NETLINK. The NETLINK name is not
49  * used in order to avoid confusion between Zephyr and Linux as the
50  * implementations are different.
51  *
52  * The socket domain (address family) is AF_NET_MGMT, and the type of socket
53  * is either SOCK_RAW or SOCK_DGRAM, because this is a datagram-oriented
54  * service.
55  *
56  * The protocol (protocol type) selects for which feature the socket is used.
57  *
58  * When used with bind(), the nm_pid field of the sockaddr_nm can be
59  * filled with the calling thread' own id. The nm_pid serves here as the local
60  * address of this net_mgmt socket. The application is responsible for picking
61  * a unique integer value to fill in nm_pid.
62  */
63 struct sockaddr_nm {
64 	/** AF_NET_MGMT address family. */
65 	sa_family_t nm_family;
66 
67 	/** Network interface related to this address */
68 	int nm_ifindex;
69 
70 	/** Thread id or similar that is used to separate the different
71 	 * sockets. Application can decide how the pid is constructed.
72 	 */
73 	uintptr_t nm_pid;
74 
75 	/** net_mgmt mask */
76 	uint32_t nm_mask;
77 };
78 
79 
80 /**
81  * Each network management message is prefixed with this header.
82  */
83 struct net_mgmt_msghdr {
84 	/** Network management version */
85 	uint32_t nm_msg_version;
86 
87 	/** Length of the data */
88 	uint32_t nm_msg_len;
89 
90 	/** The actual message data follows */
91 	uint8_t nm_msg[];
92 };
93 
94 /**
95  * Version of the message is placed to the header. Currently we have
96  * following versions.
97  *
98  * Network management message versions:
99  *
100  *  0x0001 : The net_mgmt event info message follows directly
101  *           after the header.
102  */
103 #define NET_MGMT_SOCKET_VERSION_1 0x0001
104 
105 /**
106  * @}
107  */
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* ZEPHYR_INCLUDE_NET_SOCKET_NET_MGMT_H_ */
114