1
1
use core:: pin:: pin;
2
2
3
- use edge_nal:: UdpBind ;
4
-
5
3
use embassy_futures:: select:: { select, select3} ;
6
4
7
5
use rs_matter:: dm:: clusters:: gen_comm:: CommPolicy ;
@@ -16,6 +14,7 @@ use rs_matter::transport::network::NoNetwork;
16
14
use rs_matter:: utils:: init:: { init, Init } ;
17
15
use rs_matter:: utils:: select:: Coalesce ;
18
16
17
+ use crate :: nal:: NetStack ;
19
18
use crate :: network:: { Embedding , Network } ;
20
19
use crate :: persist:: { KvBlobStore , SharedKvBlobStore } ;
21
20
use crate :: private:: Sealed ;
@@ -63,25 +62,25 @@ where
63
62
pub type EthMatterStack < ' a , E = ( ) > = MatterStack < ' a , Eth < E > > ;
64
63
65
64
/// A trait representing a task that needs access to the operational Ethernet interface
66
- /// (Netif and UDP stack ) to perform its work.
65
+ /// (Network stack and Netif ) to perform its work.
67
66
pub trait EthernetTask {
68
- /// Run the task with the given network interface and UDP stack
69
- async fn run < U , N > ( & mut self , udp : U , netif : N ) -> Result < ( ) , Error >
67
+ /// Run the task with the given network stack and network interface
68
+ async fn run < S , N > ( & mut self , net_stack : S , netif : N ) -> Result < ( ) , Error >
70
69
where
71
- U : UdpBind ,
70
+ S : NetStack ,
72
71
N : NetifDiag + NetChangeNotif ;
73
72
}
74
73
75
74
impl < T > EthernetTask for & mut T
76
75
where
77
76
T : EthernetTask ,
78
77
{
79
- async fn run < U , N > ( & mut self , udp : U , netif : N ) -> Result < ( ) , Error >
78
+ async fn run < S , N > ( & mut self , net_stack : S , netif : N ) -> Result < ( ) , Error >
80
79
where
81
- U : UdpBind ,
80
+ S : NetStack ,
82
81
N : NetifDiag + NetChangeNotif ,
83
82
{
84
- ( * self ) . run ( udp , netif) . await
83
+ ( * self ) . run ( net_stack , netif) . await
85
84
}
86
85
}
87
86
@@ -107,28 +106,28 @@ where
107
106
108
107
/// A utility type for running an ethernet task with a pre-existing ethernet interface
109
108
/// rather than bringing up / tearing down the ethernet interface for the task.
110
- pub struct PreexistingEthernet < U , N > {
111
- udp : U ,
109
+ pub struct PreexistingEthernet < S , N > {
110
+ stack : S ,
112
111
netif : N ,
113
112
}
114
113
115
- impl < N , U > PreexistingEthernet < U , N > {
114
+ impl < S , N > PreexistingEthernet < S , N > {
116
115
/// Create a new `PreexistingEthernet` instance with the given network interface and UDP stack.
117
- pub const fn new ( udp : U , netif : N ) -> Self {
118
- Self { udp , netif }
116
+ pub const fn new ( stack : S , netif : N ) -> Self {
117
+ Self { stack , netif }
119
118
}
120
119
}
121
120
122
- impl < U , N > Ethernet for PreexistingEthernet < U , N >
121
+ impl < S , N > Ethernet for PreexistingEthernet < S , N >
123
122
where
124
- U : UdpBind ,
123
+ S : NetStack ,
125
124
N : NetifDiag + NetChangeNotif ,
126
125
{
127
126
async fn run < T > ( & mut self , mut task : T ) -> Result < ( ) , Error >
128
127
where
129
128
T : EthernetTask ,
130
129
{
131
- task. run ( & mut self . udp , & self . netif ) . await
130
+ task. run ( & self . stack , & self . netif ) . await
132
131
}
133
132
}
134
133
@@ -172,27 +171,32 @@ where
172
171
///
173
172
/// Parameters:
174
173
/// - `netif` - a user-provided `Netif` implementation for the Ethernet network
175
- /// - `udp ` - a user-provided `UdpBind` implementation
174
+ /// - `net_stack ` - a user-provided network stack implementation
176
175
/// - `persist` - a user-provided `Persist` implementation
177
176
/// - `handler` - a user-provided DM handler implementation
178
177
/// - `user` - a user-provided future that will be polled only when the netif interface is up
179
178
pub async fn run_preex < U , N , S , H , X > (
180
179
& self ,
181
- udp : U ,
180
+ net_stack : U ,
182
181
netif : N ,
183
182
store : & SharedKvBlobStore < ' _ , S > ,
184
183
handler : H ,
185
184
user : X ,
186
185
) -> Result < ( ) , Error >
187
186
where
187
+ U : NetStack ,
188
188
N : NetifDiag + NetChangeNotif ,
189
- U : UdpBind ,
190
189
S : KvBlobStore ,
191
190
H : AsyncHandler + AsyncMetadata ,
192
191
X : UserTask ,
193
192
{
194
- self . run ( PreexistingEthernet :: new ( udp, netif) , store, handler, user)
195
- . await
193
+ self . run (
194
+ PreexistingEthernet :: new ( net_stack, netif) ,
195
+ store,
196
+ handler,
197
+ user,
198
+ )
199
+ . await
196
200
}
197
201
198
202
/// Run the Matter stack for an Ethernet network.
@@ -257,15 +261,15 @@ where
257
261
H : AsyncMetadata + AsyncHandler ,
258
262
X : UserTask ,
259
263
{
260
- async fn run < U , C > ( & mut self , udp : U , netif : C ) -> Result < ( ) , Error >
264
+ async fn run < S , C > ( & mut self , net_stack : S , netif : C ) -> Result < ( ) , Error >
261
265
where
262
- U : UdpBind ,
266
+ S : NetStack ,
263
267
C : NetifDiag + NetChangeNotif ,
264
268
{
265
269
info ! ( "Ethernet driver started" ) ;
266
270
267
271
let mut net_task = pin ! ( self . 0 . run_oper_net(
268
- & udp ,
272
+ & net_stack ,
269
273
& netif,
270
274
core:: future:: pending( ) ,
271
275
Option :: <( NoNetwork , NoNetwork ) >:: None ,
@@ -274,7 +278,7 @@ where
274
278
let handler = self . 0 . root_handler ( & ( ) , & true , & netif, & self . 1 ) ;
275
279
let mut handler_task = pin ! ( self . 0 . run_handler( ( & self . 1 , handler) ) ) ;
276
280
277
- let mut user_task = pin ! ( self . 2 . run( & udp , & netif) ) ;
281
+ let mut user_task = pin ! ( self . 2 . run( & net_stack , & netif) ) ;
278
282
279
283
select3 ( & mut net_task, & mut handler_task, & mut user_task)
280
284
. coalesce ( )
0 commit comments