1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021 Felix Fietkau <nbd@nbd.name> */
5 static LIST_HEAD(clients
);
7 void rcd_client_set_phy_state(struct client
*cl
, struct phy
*phy
, bool add
)
10 list_for_each_entry(cl
, &clients
, list
)
11 rcd_client_set_phy_state(cl
, phy
, add
);
15 if (add
&& !cl
->init_done
) {
16 rcd_phy_dump(cl
, phy
);
20 client_phy_printf(cl
, phy
, "0;%s\n", add
? "add" : "remove");
23 void rcd_client_phy_event(struct phy
*phy
, const char *str
)
27 list_for_each_entry(cl
, &clients
, list
)
28 client_phy_printf(cl
, phy
, "%s\n", str
);
32 client_start(struct client
*cl
)
36 vlist_for_each_element(&phy_list
, phy
, node
)
37 rcd_client_set_phy_state(cl
, phy
, true);
41 client_handle_data(struct client
*cl
, char *data
)
46 while ((sep
= strchr(data
, '\n')) != NULL
) {
47 len
+= sep
- data
+ 1;
51 rcd_phy_control(cl
, data
);
59 client_notify_read(struct ustream
*s
, int bytes
)
61 struct client
*cl
= container_of(s
, struct client
, sfd
.stream
);
66 data
= ustream_get_read_buf(s
, &len
);
70 len
= client_handle_data(cl
, data
);
74 ustream_consume(s
, len
);
79 client_notify_state(struct ustream
*s
)
81 struct client
*cl
= container_of(s
, struct client
, sfd
.stream
);
83 if (!s
->write_error
&& !s
->eof
)
92 void rcd_client_accept(int fd
)
97 cl
= calloc(1, sizeof(*cl
));
99 us
->notify_read
= client_notify_read
;
100 us
->notify_state
= client_notify_state
;
101 us
->string_data
= true;
102 ustream_fd_init(&cl
->sfd
, fd
);
103 list_add_tail(&cl
->list
, &clients
);