Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
midi2.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Titouan Christophe
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#ifndef ZEPHYR_INCLUDE_NET_MIDI2_H_
7#define ZEPHYR_INCLUDE_NET_MIDI2_H_
8
16
29
30
31#include <stdint.h>
32#include <zephyr/audio/midi.h>
33#include <zephyr/net/socket.h>
34#include <zephyr/posix/poll.h>
35
40#define NETMIDI2_NONCE_SIZE 16
41
50#define NETMIDI2_EP_DEFINE(_var_name, _ep_name, _piid, _port) \
51 static struct netmidi2_ep _var_name = { \
52 .name = (_ep_name), \
53 .piid = (_piid), \
54 .addr4.sin_port = (_port), \
55 .auth_type = NETMIDI2_AUTH_NONE, \
56 }
57
68#define NETMIDI2_EP_DEFINE_WITH_AUTH(_var_name, _ep_name, _piid, _port, _secret) \
69 static struct netmidi2_ep _var_name = { \
70 .name = (_ep_name), \
71 .piid = (_piid), \
72 .addr4.sin_port = (_port), \
73 .auth_type = NETMIDI2_AUTH_SHARED_SECRET, \
74 .shared_auth_secret = (_secret), \
75 }
76
94#define NETMIDI2_EP_DEFINE_WITH_USERS(_var_name, _ep_name, _piid, _port, ...) \
95 static const struct netmidi2_userlist users_of_##_var_name = { \
96 .n_users = ARRAY_SIZE(((struct netmidi2_user []) { __VA_ARGS__ })), \
97 .users = { __VA_ARGS__ }, \
98 }; \
99 static struct netmidi2_ep _var_name = { \
100 .name = (_ep_name), \
101 .piid = (_piid), \
102 .addr4.sin_port = (_port), \
103 .auth_type = NETMIDI2_AUTH_USER_PASSWORD, \
104 .userlist = &users_of_##_var_name, \
105 }
106
107struct netmidi2_ep;
108
114 const char *name;
116 const char *password;
117};
118
124 size_t n_users;
126 const struct netmidi2_user users[];
127};
128
189
201
207 const char *name;
209 const char *piid;
211 union {
215 };
219 void (*rx_packet_cb)(struct netmidi2_session *session,
220 const struct midi_ump ump);
222 struct netmidi2_session peers[CONFIG_NETMIDI2_HOST_MAX_CLIENTS];
227#if defined(CONFIG_NETMIDI2_HOST_AUTH) || defined(__DOXYGEN__)
228 union {
233 };
234#endif
235};
236
243
249void netmidi2_broadcast(struct netmidi2_ep *ep, const struct midi_ump ump);
250
256void netmidi2_send(struct netmidi2_session *sess, const struct midi_ump ump);
257
259
260#endif
uint32_t socklen_t
Length of a socket address.
Definition net_ip.h:172
void netmidi2_send(struct netmidi2_session *sess, const struct midi_ump ump)
Send a Universal MIDI Packet to a single client.
void netmidi2_broadcast(struct netmidi2_ep *ep, const struct midi_ump ump)
Send a Universal MIDI Packet to all clients connected to the endpoint.
#define NETMIDI2_NONCE_SIZE
Size, in bytes, of the nonce sent to the client for authentication.
Definition midi2.h:40
int netmidi2_host_ep_start(struct netmidi2_ep *ep)
Start hosting a network (UDP) Universal MIDI Packet endpoint.
netmidi2_auth_type
Type of authentication in Network MIDI2.
Definition midi2.h:193
@ NETMIDI2_AUTH_SHARED_SECRET
Authentication with a shared secret key.
Definition midi2.h:197
@ NETMIDI2_AUTH_USER_PASSWORD
Authentication with username and password.
Definition midi2.h:199
@ NETMIDI2_AUTH_NONE
No authentication required.
Definition midi2.h:195
BSD Sockets compatible API definitions.
state
Definition parser_state.h:29
#define pollfd
Definition poll.h:17
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
A structure used to submit work.
Definition kernel.h:4293
Universal MIDI Packet container.
Definition midi.h:41
Network buffer representation.
Definition net_buf.h:1006
A Network MIDI2.0 Endpoint.
Definition midi2.h:205
const struct netmidi2_userlist * userlist
A list of users/passwords.
Definition midi2.h:232
const char * name
The endpoint name.
Definition midi2.h:207
struct sockaddr_in6 addr6
Definition midi2.h:214
struct sockaddr addr
Definition midi2.h:212
const char * shared_auth_secret
A shared authentication key.
Definition midi2.h:230
struct sockaddr_in addr4
Definition midi2.h:213
struct zsock_pollfd pollsock
The listening socket wrapped in a poll descriptor.
Definition midi2.h:217
void(* rx_packet_cb)(struct netmidi2_session *session, const struct midi_ump ump)
The function to call when data is received from a client.
Definition midi2.h:219
const char * piid
The endpoint product instance id.
Definition midi2.h:209
struct netmidi2_session peers[CONFIG_NETMIDI2_HOST_MAX_CLIENTS]
List of peers to this endpoint.
Definition midi2.h:222
enum netmidi2_auth_type auth_type
The type of authentication required to establish a session with this host endpoint.
Definition midi2.h:226
A Network MIDI2 session, representing a connection to a peer.
Definition midi2.h:132
const struct netmidi2_user * user
The username to which this session belongs.
Definition midi2.h:180
@ NETMIDI2_SESSION_PENDING_INVITATION
Client has sent Invitation, however the Host has not accepted the Invitation.
Definition midi2.h:149
@ NETMIDI2_SESSION_PENDING_RESET
One Device has sent the Session Reset Command and is waiting for Session Reset Reply,...
Definition midi2.h:162
@ NETMIDI2_SESSION_AUTH_REQUIRED
Host has replied with Invitation Reply: Authentication Required or Invitation Reply: User Authenticat...
Definition midi2.h:155
@ NETMIDI2_SESSION_NOT_INITIALIZED
The session is not in use.
Definition midi2.h:139
@ NETMIDI2_SESSION_IDLE
Device may be aware of each other (e.g.
Definition midi2.h:144
@ NETMIDI2_SESSION_PENDING_BYE
one Endpoint has sent Bye and is waiting for Bye Reply, and a timeout has not yet occurred.
Definition midi2.h:166
@ NETMIDI2_SESSION_ESTABLISHED
Invitation accepted, UMP Commands can be exchanged.
Definition midi2.h:157
struct net_buf * tx_buf
The transmission buffer for that peer.
Definition midi2.h:185
struct k_work tx_work
The transmission work for that peer.
Definition midi2.h:187
uint16_t tx_ump_seq
Sequence number of the next universal MIDI packet to send.
Definition midi2.h:169
char nonce[16]
The crypto nonce used to authorize this session.
Definition midi2.h:182
struct netmidi2_ep * ep
The Network MIDI2 endpoint to which this session belongs.
Definition midi2.h:177
socklen_t addr_len
Length of the peer's remote address.
Definition midi2.h:175
struct sockaddr_storage addr
Remote address of the peer.
Definition midi2.h:173
uint16_t rx_ump_seq
Sequence number of the next universal MIDI packet to receive.
Definition midi2.h:171
A username/password pair for user-based authentication.
Definition midi2.h:112
const char * name
The user name for authentication.
Definition midi2.h:114
const char * password
The password for authentication.
Definition midi2.h:116
A list of users for user-based authentication.
Definition midi2.h:122
size_t n_users
Number of users in the list.
Definition midi2.h:124
const struct netmidi2_user users[]
The user/password pairs.
Definition midi2.h:126
Socket address struct for IPv6.
Definition net_ip.h:182
Socket address struct for IPv4.
Definition net_ip.h:190
Generic sockaddr struct.
Definition net_ip.h:410