aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json12
-rw-r--r--embassy-net/Cargo.toml4
-rw-r--r--embassy-net/src/lib.rs4
-rw-r--r--embassy-net/src/raw.rs64
4 files changed, 13 insertions, 71 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0c195a13b..343331950 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -10,24 +10,24 @@
10 "rust-analyzer.cargo.noDefaultFeatures": true, 10 "rust-analyzer.cargo.noDefaultFeatures": true,
11 "rust-analyzer.showUnlinkedFileNotification": false, 11 "rust-analyzer.showUnlinkedFileNotification": false,
12 // uncomment the target of your chip. 12 // uncomment the target of your chip.
13 //"rust-analyzer.cargo.target": "thumbv6m-none-eabi", 13 "rust-analyzer.cargo.target": "thumbv6m-none-eabi",
14 //"rust-analyzer.cargo.target": "thumbv7m-none-eabi", 14 //"rust-analyzer.cargo.target": "thumbv7m-none-eabi",
15 "rust-analyzer.cargo.target": "thumbv7em-none-eabi", 15 //"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
16 //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", 16 //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
17 "rust-analyzer.cargo.features": [ 17 /* "rust-analyzer.cargo.features": [
18 "stm32f103c8", 18 "stm32f103c8",
19 "time-driver-any", 19 "time-driver-any",
20 "unstable-pac", 20 "unstable-pac",
21 "exti", 21 "exti",
22 ], 22 ], */
23 "rust-analyzer.linkedProjects": [ 23 "rust-analyzer.linkedProjects": [
24 // Uncomment ONE line for the chip you want to work on. 24 // Uncomment ONE line for the chip you want to work on.
25 // This makes rust-analyzer work on the example crate and all its dependencies. 25 // This makes rust-analyzer work on the example crate and all its dependencies.
26 "embassy-stm32/Cargo.toml", 26 // "embassy-stm32/Cargo.toml",
27 // "examples/nrf52840-rtic/Cargo.toml", 27 // "examples/nrf52840-rtic/Cargo.toml",
28 // "examples/nrf5340/Cargo.toml", 28 // "examples/nrf5340/Cargo.toml",
29 // "examples/nrf-rtos-trace/Cargo.toml", 29 // "examples/nrf-rtos-trace/Cargo.toml",
30 // "examples/rp/Cargo.toml", 30 "examples/rp/Cargo.toml",
31 // "examples/std/Cargo.toml", 31 // "examples/std/Cargo.toml",
32 // "examples/stm32c0/Cargo.toml", 32 // "examples/stm32c0/Cargo.toml",
33 // "examples/stm32f0/Cargo.toml", 33 // "examples/stm32f0/Cargo.toml",
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml
index 47faaa205..ee7289ad8 100644
--- a/embassy-net/Cargo.toml
+++ b/embassy-net/Cargo.toml
@@ -16,11 +16,11 @@ categories = [
16[package.metadata.embassy_docs] 16[package.metadata.embassy_docs]
17src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/" 17src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/"
18src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/" 18src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/"
19features = ["defmt", "tcp", "udp","raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"] 19features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"]
20target = "thumbv7em-none-eabi" 20target = "thumbv7em-none-eabi"
21 21
22[package.metadata.docs.rs] 22[package.metadata.docs.rs]
23features = ["defmt", "tcp", "udp", "raw","dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"] 23features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"]
24 24
25[features] 25[features]
26default = [] 26default = []
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 05c8aec7b..86ced1ded 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -15,13 +15,13 @@ pub(crate) mod fmt;
15mod device; 15mod device;
16#[cfg(feature = "dns")] 16#[cfg(feature = "dns")]
17pub mod dns; 17pub mod dns;
18#[cfg(feature = "raw")]
19pub mod raw;
18#[cfg(feature = "tcp")] 20#[cfg(feature = "tcp")]
19pub mod tcp; 21pub mod tcp;
20mod time; 22mod time;
21#[cfg(feature = "udp")] 23#[cfg(feature = "udp")]
22pub mod udp; 24pub mod udp;
23#[cfg(feature = "raw")]
24pub mod raw;
25 25
26use core::cell::RefCell; 26use core::cell::RefCell;
27use core::future::{poll_fn, Future}; 27use core::future::{poll_fn, Future};
diff --git a/embassy-net/src/raw.rs b/embassy-net/src/raw.rs
index a0e458fff..ad8d69853 100644
--- a/embassy-net/src/raw.rs
+++ b/embassy-net/src/raw.rs
@@ -13,28 +13,6 @@ use smoltcp::wire::{IpProtocol, IpVersion};
13 13
14use crate::{SocketStack, Stack}; 14use crate::{SocketStack, Stack};
15 15
16
17/// Unrelavent for RawSocket?
18/* /// Error returned by [`RawSocket::bind`].
19#[derive(PartialEq, Eq, Clone, Copy, Debug)]
20#[cfg_attr(feature = "defmt", derive(defmt::Format))]
21pub enum BindError {
22 /// The socket was already open.
23 InvalidState,
24 /// No route to host.
25 NoRoute,
26} */
27
28/// Error returned by [`RawSocket::recv_from`] and [`RawSocket::send_to`].
29#[derive(PartialEq, Eq, Clone, Copy, Debug)]
30#[cfg_attr(feature = "defmt", derive(defmt::Format))]
31pub enum SendError {
32 /// No route to host.
33 NoRoute,
34 /// Socket not bound to an outgoing port.
35 SocketNotBound,
36}
37
38/// Error returned by [`RawSocket::recv`] and [`RawSocket::send`]. 16/// Error returned by [`RawSocket::recv`] and [`RawSocket::send`].
39#[derive(PartialEq, Eq, Clone, Copy, Debug)] 17#[derive(PartialEq, Eq, Clone, Copy, Debug)]
40#[cfg_attr(feature = "defmt", derive(defmt::Format))] 18#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -87,42 +65,6 @@ impl<'a> RawSocket<'a> {
87 res 65 res
88 } 66 }
89 67
90 /// Bind the socket to a local endpoint.
91 ///
92 /// How to handle this in RawSocket? no need for bind?
93 ///
94 /* pub fn bind<T>(&mut self, endpoint: T) -> Result<(), BindError>
95 where
96 T: Into<IpListenEndpoint>,
97 {
98 let mut endpoint = endpoint.into();
99
100 if endpoint.port == 0 {
101 // If user didn't specify port allocate a dynamic port.
102 endpoint.port = self.stack.borrow_mut().get_local_port();
103 }
104
105 match self.with_mut(|s, _| s.bind(endpoint)) {
106 Ok(()) => Ok(()),
107 Err(raw::BindError::InvalidState) => Err(BindError::InvalidState),
108 Err(raw::BindError::Unaddressable) => Err(BindError::NoRoute),
109 }
110 }
111
112 fn with<R>(&self, f: impl FnOnce(&raw::Socket, &Interface) -> R) -> R {
113 let s = &*self.stack.borrow();
114 let socket = s.sockets.get::<raw::Socket>(self.handle);
115 f(socket, &s.iface)
116 }
117
118 fn with_mut<R>(&self, f: impl FnOnce(&mut raw::Socket, &mut Interface) -> R) -> R {
119 let s = &mut *self.stack.borrow_mut();
120 let socket = s.sockets.get_mut::<raw::Socket>(self.handle);
121 let res = f(socket, &mut s.iface);
122 s.waker.wake();
123 res
124 } */
125
126 /// Receive a datagram. 68 /// Receive a datagram.
127 /// 69 ///
128 /// This method will wait until a datagram is received. 70 /// This method will wait until a datagram is received.
@@ -149,7 +91,7 @@ impl<'a> RawSocket<'a> {
149 /// Send a datagram. 91 /// Send a datagram.
150 /// 92 ///
151 /// This method will wait until the datagram has been sent.` 93 /// This method will wait until the datagram has been sent.`
152 pub async fn send<T>(&self, buf: &[u8]) -> Result<(), SendError> { 94 pub async fn send<T>(&self, buf: &[u8]) -> Result<(), raw::SendError> {
153 poll_fn(move |cx| self.poll_send(buf, cx)).await 95 poll_fn(move |cx| self.poll_send(buf, cx)).await
154 } 96 }
155 97
@@ -159,7 +101,7 @@ impl<'a> RawSocket<'a> {
159 /// 101 ///
160 /// When the socket's send buffer is full, this method will return `Poll::Pending` 102 /// When the socket's send buffer is full, this method will return `Poll::Pending`
161 /// and register the current task to be notified when the buffer has space available. 103 /// and register the current task to be notified when the buffer has space available.
162 pub fn poll_send(&self, buf: &[u8], cx: &mut Context<'_>) -> Poll<Result<(), SendError>>{ 104 pub fn poll_send(&self, buf: &[u8], cx: &mut Context<'_>) -> Poll<Result<(), raw::SendError>> {
163 self.with_mut(|s, _| match s.send_slice(buf) { 105 self.with_mut(|s, _| match s.send_slice(buf) {
164 // Entire datagram has been sent 106 // Entire datagram has been sent
165 Ok(()) => Poll::Ready(Ok(())), 107 Ok(()) => Poll::Ready(Ok(())),
@@ -169,7 +111,7 @@ impl<'a> RawSocket<'a> {
169 } 111 }
170 }) 112 })
171 } 113 }
172 } 114}
173 115
174impl Drop for RawSocket<'_> { 116impl Drop for RawSocket<'_> {
175 fn drop(&mut self) { 117 fn drop(&mut self) {