cat_dev/fsemul/sdio/mod.rs
1//! Clients, and Protocols for interacting with the CAT-DEV's SDIO.
2//!
3//! Unlike traditional SDIO which is usually low-level firmware level protocol
4//! that involves things like individual bits for the protocol, the CAT-DEV
5//! takes a very 'interesting' approach to what they call SDIO.
6//!
7//! Specifically the first thing to note is that, "SDIO" can refer to two
8//! ports on your CAT-DEV. There is "SDIO Printf/Control" (by default port
9//! 7975), and "SDIO Block Data" (by default port 7976), which actually
10//! interact over two totally independent TCP streams.
11
12#[cfg_attr(docsrs, doc(cfg(feature = "clients")))]
13#[cfg(feature = "clients")]
14pub mod client;
15#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
16#[cfg(any(feature = "clients", feature = "servers"))]
17pub(crate) mod data_stream;
18pub mod errors;
19#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
20#[cfg(any(feature = "clients", feature = "servers"))]
21pub mod proto;
22#[cfg_attr(docsrs, doc(cfg(feature = "servers")))]
23#[cfg(feature = "servers")]
24pub mod server;
25
26use std::time::Duration;
27
28#[cfg(any(feature = "clients", feature = "servers"))]
29use scc::HashMap as ConcurrentHashMap;
30#[cfg(any(feature = "clients", feature = "servers"))]
31use std::sync::LazyLock;
32
33/// The default port to use for "SDIO Printf/Control" communications.
34///
35/// It should be noted that a human can override this port in the MION itself.
36/// However, most nintendo tools don't get this param from the MION itself, and
37/// expect it to also be set in `fsemul.ini`.
38pub const DEFAULT_SDIO_CONTROL_PORT: u16 = 7975;
39/// The default port to use for "SDIO Block Data" communications.
40///
41/// It should be noted that a human can override this port in the MION itself.
42/// However, most nintendo tools don't get this param from the MION itself, and
43/// expect it to also be set in `fsemul.ini`.
44pub const DEFAULT_SDIO_BLOCK_PORT: u16 = 7976;
45
46/// The timeout to initiate a TCP connection to SDIO.
47pub const CONNECT_TIMEOUT: Duration = Duration::from_secs(15);
48
49/// Underlying 'data' streams for a series of <stream id, data stream>.
50///
51/// The data stream is truly just a data stream, all the benefits of having
52/// this in a tcp client, or server, etc. just doesn't exist. It is an
53/// arbitrary stream of bytes in ever since of the word.
54///
55/// This gets populated on SDIO Control stream start, and cleaned up on SDIO
56/// Control stream end.
57#[cfg(any(feature = "clients", feature = "servers"))]
58static SDIO_DATA_STREAMS: LazyLock<ConcurrentHashMap<u64, data_stream::DataStream>> =
59 LazyLock::new(|| ConcurrentHashMap::with_capacity(1));