1
- use core:: { cell:: RefCell , mem :: MaybeUninit , pin:: pin} ;
1
+ use core:: { cell:: RefCell , pin:: pin} ;
2
2
3
3
use domain:: base:: name:: FromStrError ;
4
4
use domain:: base:: { octets:: ParseError , ShortBuf } ;
5
- use embassy_futures:: select:: { select, select3 } ;
5
+ use embassy_futures:: select:: select;
6
6
use embassy_time:: { Duration , Timer } ;
7
7
use log:: info;
8
8
9
9
use crate :: data_model:: cluster_basic_information:: BasicInfoConfig ;
10
10
use crate :: error:: { Error , ErrorCode } ;
11
11
use crate :: transport:: network:: { Address , IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ;
12
- use crate :: transport:: packet:: { MAX_RX_BUF_SIZE , MAX_TX_BUF_SIZE } ;
13
12
use crate :: transport:: pipe:: { Chunk , Pipe } ;
14
- use crate :: transport:: udp:: UdpListener ;
15
13
use crate :: utils:: select:: { EitherUnwrap , Notification } ;
16
14
17
15
use super :: {
18
16
proto:: { Host , Services } ,
19
17
Service , ServiceMode ,
20
18
} ;
21
19
22
- const IP_BIND_ADDR : IpAddr = IpAddr :: V6 ( Ipv6Addr :: UNSPECIFIED ) ;
23
-
24
20
const IP_BROADCAST_ADDR : Ipv4Addr = Ipv4Addr :: new ( 224 , 0 , 0 , 251 ) ;
25
21
const IPV6_BROADCAST_ADDR : Ipv6Addr = Ipv6Addr :: new ( 0xff02 , 0 , 0 , 0 , 0 , 0 , 0 , 0x00fb ) ;
26
22
27
23
const PORT : u16 = 5353 ;
28
24
29
- type MdnsTxBuf = MaybeUninit < [ u8 ; MAX_TX_BUF_SIZE ] > ;
30
- type MdnsRxBuf = MaybeUninit < [ u8 ; MAX_RX_BUF_SIZE ] > ;
31
-
32
25
pub struct Mdns < ' a > {
33
26
host : Host < ' a > ,
27
+ #[ allow( unused) ]
34
28
interface : u32 ,
35
29
dev_det : & ' a BasicInfoConfig < ' a > ,
36
30
matter_port : u16 ,
@@ -108,9 +102,21 @@ impl<'a> MdnsRunner<'a> {
108
102
Self ( mdns)
109
103
}
110
104
111
- pub async fn run_udp ( & mut self ) -> Result < ( ) , Error > {
112
- let mut tx_buf = MdnsTxBuf :: uninit ( ) ;
113
- let mut rx_buf = MdnsRxBuf :: uninit ( ) ;
105
+ #[ cfg( any( feature = "std" , feature = "embassy-net" ) ) ]
106
+ pub async fn run_udp < D > (
107
+ & mut self ,
108
+ stack : & crate :: transport:: network:: NetworkStack < D > ,
109
+ buffers : & mut crate :: transport:: udp:: UdpBuffers ,
110
+ ) -> Result < ( ) , Error >
111
+ where
112
+ D : crate :: transport:: network:: NetworkStackMulticastDriver
113
+ + crate :: transport:: network:: NetworkStackDriver
114
+ + ' static ,
115
+ {
116
+ let mut tx_buf =
117
+ core:: mem:: MaybeUninit :: < [ u8 ; crate :: transport:: packet:: MAX_TX_BUF_SIZE ] > :: uninit ( ) ;
118
+ let mut rx_buf =
119
+ core:: mem:: MaybeUninit :: < [ u8 ; crate :: transport:: packet:: MAX_RX_BUF_SIZE ] > :: uninit ( ) ;
114
120
115
121
let tx_buf = & mut tx_buf;
116
122
let rx_buf = & mut rx_buf;
@@ -121,10 +127,18 @@ impl<'a> MdnsRunner<'a> {
121
127
let tx_pipe = & tx_pipe;
122
128
let rx_pipe = & rx_pipe;
123
129
124
- let mut udp = UdpListener :: new ( SocketAddr :: new ( IP_BIND_ADDR , PORT ) ) . await ?;
130
+ let mut udp = crate :: transport:: udp:: UdpListener :: new (
131
+ stack,
132
+ crate :: transport:: network:: SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: UNSPECIFIED ) , PORT ) ,
133
+ buffers,
134
+ )
135
+ . await ?;
125
136
126
137
udp. join_multicast_v6 ( IPV6_BROADCAST_ADDR , self . 0 . interface ) ?;
127
- udp. join_multicast_v4 ( IP_BROADCAST_ADDR , Ipv4Addr :: from ( self . 0 . host . ip ) ) ?;
138
+ udp. join_multicast_v4 (
139
+ IP_BROADCAST_ADDR ,
140
+ crate :: transport:: network:: Ipv4Addr :: from ( self . 0 . host . ip ) ,
141
+ ) ?;
128
142
129
143
let udp = & udp;
130
144
@@ -168,7 +182,9 @@ impl<'a> MdnsRunner<'a> {
168
182
169
183
let mut run = pin ! ( async move { self . run( tx_pipe, rx_pipe) . await } ) ;
170
184
171
- select3 ( & mut tx, & mut rx, & mut run) . await . unwrap ( )
185
+ embassy_futures:: select:: select3 ( & mut tx, & mut rx, & mut run)
186
+ . await
187
+ . unwrap ( )
172
188
}
173
189
174
190
pub async fn run ( & self , tx_pipe : & Pipe < ' _ > , rx_pipe : & Pipe < ' _ > ) -> Result < ( ) , Error > {
0 commit comments