minstrel-rcd: add work-in-progress minstrel remote control daemon
[openwrt/staging/nbd.git] / package / utils / minstrel-rcd / src / rcd.h
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021 Felix Fietkau <nbd@nbd.name> */
3 #ifndef __MINSTREL_RCD_H
4 #define __MINSTREL_RCD_H
5
6 #include <libubox/list.h>
7 #include <libubox/vlist.h>
8 #include <libubox/uloop.h>
9 #include <libubox/ustream.h>
10 #include <libubox/utils.h>
11 #include <stdbool.h>
12 #include <stdint.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <unistd.h>
17
18 #define RCD_PORT 0x5243
19
20 struct phy {
21 struct vlist_node node;
22
23 struct uloop_fd event_fd;
24 int control_fd;
25 };
26
27 struct client {
28 struct list_head list;
29 struct ustream_fd sfd;
30 bool init_done;
31 };
32
33 struct server {
34 struct list_head list;
35 struct uloop_fd fd;
36 const char *addr;
37 };
38
39 static inline const char *phy_name(struct phy *phy)
40 {
41 return phy->node.avl.key;
42 }
43
44 extern struct vlist_tree phy_list;
45
46 void rcd_server_add(const char *addr);
47 void rcd_server_init(void);
48
49 void rcd_client_accept(int fd);
50 void rcd_client_phy_event(struct phy *phy, const char *str);
51 void rcd_client_set_phy_state(struct client *cl, struct phy *phy, bool add);
52
53 void rcd_phy_init(void);
54 void rcd_phy_init_client(struct client *cl);
55 void rcd_phy_dump(struct client *cl, struct phy *phy);
56 void rcd_phy_control(struct client *cl, char *data);
57
58 #define client_printf(cl, ...) ustream_printf(&(cl)->sfd.stream, __VA_ARGS__)
59 #define client_phy_printf(cl, phy, fmt, ...) client_printf(cl, "%s;" fmt, phy_name(phy), ## __VA_ARGS__)
60
61 #endif