change MacAddress to a union instead of an enum
This commit is contained in:
parent
d5a4457b5e
commit
eccd2ecebf
@ -9,12 +9,13 @@ pub trait MacCommand {
|
|||||||
const SIZE: usize;
|
const SIZE: usize;
|
||||||
|
|
||||||
fn copy_into_slice(&self, buf: &mut [u8]) {
|
fn copy_into_slice(&self, buf: &mut [u8]) {
|
||||||
unsafe { core::ptr::copy(self as *const _ as *const u8, buf as *mut _ as *mut u8, 8) };
|
unsafe { core::ptr::copy(self as *const _ as *const u8, buf as *mut _ as *mut u8, Self::SIZE) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MLME ASSOCIATE Request used to request an association
|
/// MLME ASSOCIATE Request used to request an association
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct AssociateRequest {
|
pub struct AssociateRequest {
|
||||||
/// the logical channel on which to attempt association
|
/// the logical channel on which to attempt association
|
||||||
pub channel_number: MacChannel,
|
pub channel_number: MacChannel,
|
||||||
@ -45,6 +46,7 @@ impl MacCommand for AssociateRequest {
|
|||||||
|
|
||||||
/// MLME DISASSOCIATE Request sed to request a disassociation
|
/// MLME DISASSOCIATE Request sed to request a disassociation
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct DisassociateRequest {
|
pub struct DisassociateRequest {
|
||||||
/// device addressing mode used
|
/// device addressing mode used
|
||||||
pub device_addr_mode: AddressMode,
|
pub device_addr_mode: AddressMode,
|
||||||
@ -73,6 +75,7 @@ impl MacCommand for DisassociateRequest {
|
|||||||
|
|
||||||
/// MLME GET Request used to request a PIB value
|
/// MLME GET Request used to request a PIB value
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct GetRequest {
|
pub struct GetRequest {
|
||||||
/// the name of the PIB attribute to read
|
/// the name of the PIB attribute to read
|
||||||
pub pib_attribute: PibId,
|
pub pib_attribute: PibId,
|
||||||
@ -85,6 +88,7 @@ impl MacCommand for GetRequest {
|
|||||||
|
|
||||||
/// MLME GTS Request used to request and maintain GTSs
|
/// MLME GTS Request used to request and maintain GTSs
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct GtsRequest {
|
pub struct GtsRequest {
|
||||||
/// the characteristics of the GTS
|
/// the characteristics of the GTS
|
||||||
pub characteristics: GtsCharacteristics,
|
pub characteristics: GtsCharacteristics,
|
||||||
@ -104,6 +108,7 @@ impl MacCommand for GtsRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct ResetRequest {
|
pub struct ResetRequest {
|
||||||
/// MAC PIB attributes are set to their default values or not during reset
|
/// MAC PIB attributes are set to their default values or not during reset
|
||||||
pub set_default_pib: bool,
|
pub set_default_pib: bool,
|
||||||
@ -117,6 +122,7 @@ impl MacCommand for ResetRequest {
|
|||||||
/// MLME RX ENABLE Request used to request that the receiver is either enabled
|
/// MLME RX ENABLE Request used to request that the receiver is either enabled
|
||||||
/// for a finite period of time or disabled
|
/// for a finite period of time or disabled
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct RxEnableRequest {
|
pub struct RxEnableRequest {
|
||||||
/// the request operation can be deferred or not
|
/// the request operation can be deferred or not
|
||||||
pub defer_permit: bool,
|
pub defer_permit: bool,
|
||||||
@ -148,6 +154,7 @@ impl MacCommand for RxEnableRequest {
|
|||||||
|
|
||||||
/// MLME SCAN Request used to initiate a channel scan over a given list of channels
|
/// MLME SCAN Request used to initiate a channel scan over a given list of channels
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct ScanRequest {
|
pub struct ScanRequest {
|
||||||
/// the type of scan to be performed
|
/// the type of scan to be performed
|
||||||
pub scan_type: ScanType,
|
pub scan_type: ScanType,
|
||||||
@ -174,6 +181,7 @@ impl MacCommand for ScanRequest {
|
|||||||
|
|
||||||
/// MLME SET Request used to attempt to write the given value to the indicated PIB attribute
|
/// MLME SET Request used to attempt to write the given value to the indicated PIB attribute
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct SetRequest {
|
pub struct SetRequest {
|
||||||
/// the pointer to the value of the PIB attribute to set
|
/// the pointer to the value of the PIB attribute to set
|
||||||
pub pib_attribute_ptr: *const u8,
|
pub pib_attribute_ptr: *const u8,
|
||||||
@ -190,6 +198,7 @@ impl MacCommand for SetRequest {
|
|||||||
/// configuration
|
/// configuration
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct StartRequest {
|
pub struct StartRequest {
|
||||||
/// PAN indentifier to used by the device
|
/// PAN indentifier to used by the device
|
||||||
pub pan_id: [u8; 2],
|
pub pan_id: [u8; 2],
|
||||||
@ -233,6 +242,7 @@ impl MacCommand for StartRequest {
|
|||||||
/// MLME SYNC Request used to synchronize with the coordinator by acquiring and, if
|
/// MLME SYNC Request used to synchronize with the coordinator by acquiring and, if
|
||||||
/// specified, tracking its beacons
|
/// specified, tracking its beacons
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct SyncRequest {
|
pub struct SyncRequest {
|
||||||
/// the channel number on which to attempt coordinator synchronization
|
/// the channel number on which to attempt coordinator synchronization
|
||||||
pub channel_number: MacChannel,
|
pub channel_number: MacChannel,
|
||||||
@ -252,6 +262,7 @@ impl MacCommand for SyncRequest {
|
|||||||
|
|
||||||
/// MLME POLL Request propmts the device to request data from the coordinator
|
/// MLME POLL Request propmts the device to request data from the coordinator
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct PollRequest {
|
pub struct PollRequest {
|
||||||
/// addressing mode of the coordinator
|
/// addressing mode of the coordinator
|
||||||
pub coord_addr_mode: AddressMode,
|
pub coord_addr_mode: AddressMode,
|
||||||
@ -277,6 +288,7 @@ impl MacCommand for PollRequest {
|
|||||||
/// MLME DPS Request allows the next higher layer to request that the PHY utilize a
|
/// MLME DPS Request allows the next higher layer to request that the PHY utilize a
|
||||||
/// given pair of preamble codes for a single use pending expiration of the DPSIndexDuration
|
/// given pair of preamble codes for a single use pending expiration of the DPSIndexDuration
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct DpsRequest {
|
pub struct DpsRequest {
|
||||||
/// the index value for the transmitter
|
/// the index value for the transmitter
|
||||||
tx_dps_index: u8,
|
tx_dps_index: u8,
|
||||||
@ -295,6 +307,7 @@ impl MacCommand for DpsRequest {
|
|||||||
/// MLME SOUNDING request primitive which is used by the next higher layer to request that
|
/// MLME SOUNDING request primitive which is used by the next higher layer to request that
|
||||||
/// the PHY respond with channel sounding information
|
/// the PHY respond with channel sounding information
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct SoundingRequest;
|
pub struct SoundingRequest;
|
||||||
|
|
||||||
impl MacCommand for SoundingRequest {
|
impl MacCommand for SoundingRequest {
|
||||||
@ -305,6 +318,7 @@ impl MacCommand for SoundingRequest {
|
|||||||
/// MLME CALIBRATE request primitive which used to obtain the results of a ranging
|
/// MLME CALIBRATE request primitive which used to obtain the results of a ranging
|
||||||
/// calibration request from an RDEV
|
/// calibration request from an RDEV
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct CalibrateRequest;
|
pub struct CalibrateRequest;
|
||||||
|
|
||||||
impl MacCommand for CalibrateRequest {
|
impl MacCommand for CalibrateRequest {
|
||||||
@ -314,6 +328,7 @@ impl MacCommand for CalibrateRequest {
|
|||||||
|
|
||||||
/// MCPS DATA Request used for MAC data related requests from the application
|
/// MCPS DATA Request used for MAC data related requests from the application
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct DataRequest {
|
pub struct DataRequest {
|
||||||
/// the handle assocated with the MSDU to be transmitted
|
/// the handle assocated with the MSDU to be transmitted
|
||||||
pub msdu_ptr: *const u8,
|
pub msdu_ptr: *const u8,
|
||||||
@ -362,6 +377,7 @@ impl MacCommand for DataRequest {
|
|||||||
|
|
||||||
/// for MCPS PURGE Request used to purge an MSDU from the transaction queue
|
/// for MCPS PURGE Request used to purge an MSDU from the transaction queue
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct PurgeRequest {
|
pub struct PurgeRequest {
|
||||||
/// the handle associated with the MSDU to be purged from the transaction
|
/// the handle associated with the MSDU to be purged from the transaction
|
||||||
/// queue
|
/// queue
|
||||||
@ -375,6 +391,7 @@ impl MacCommand for PurgeRequest {
|
|||||||
|
|
||||||
/// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication
|
/// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct AssociateResponse {
|
pub struct AssociateResponse {
|
||||||
/// extended address of the device requesting association
|
/// extended address of the device requesting association
|
||||||
pub device_address: [u8; 8],
|
pub device_address: [u8; 8],
|
||||||
@ -400,6 +417,7 @@ impl MacCommand for AssociateResponse {
|
|||||||
|
|
||||||
/// MLME ORPHAN Response used to respond to the MLME ORPHAN Indication
|
/// MLME ORPHAN Response used to respond to the MLME ORPHAN Indication
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct OrphanResponse {
|
pub struct OrphanResponse {
|
||||||
/// extended address of the orphaned device
|
/// extended address of the orphaned device
|
||||||
pub orphan_address: [u8; 8],
|
pub orphan_address: [u8; 8],
|
||||||
|
@ -141,21 +141,25 @@ impl ParseableMacEvent for CommStatusIndication {
|
|||||||
let dst_addr_mode = AddressMode::try_from(buf[3])?;
|
let dst_addr_mode = AddressMode::try_from(buf[3])?;
|
||||||
|
|
||||||
let src_address = match src_addr_mode {
|
let src_address = match src_addr_mode {
|
||||||
AddressMode::NoAddress => MacAddress::Short([0, 0]),
|
AddressMode::NoAddress => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Reserved => MacAddress::Short([0, 0]),
|
AddressMode::Reserved => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Short => MacAddress::Short([buf[4], buf[5]]),
|
AddressMode::Short => MacAddress {
|
||||||
AddressMode::Extended => {
|
short: [buf[4], buf[5]],
|
||||||
MacAddress::Extended([buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]])
|
},
|
||||||
}
|
AddressMode::Extended => MacAddress {
|
||||||
|
extended: [buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let dst_address = match dst_addr_mode {
|
let dst_address = match dst_addr_mode {
|
||||||
AddressMode::NoAddress => MacAddress::Short([0, 0]),
|
AddressMode::NoAddress => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Reserved => MacAddress::Short([0, 0]),
|
AddressMode::Reserved => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Short => MacAddress::Short([buf[12], buf[13]]),
|
AddressMode::Short => MacAddress {
|
||||||
AddressMode::Extended => {
|
short: [buf[12], buf[13]],
|
||||||
MacAddress::Extended([buf[12], buf[13], buf[14], buf[15], buf[16], buf[17], buf[18], buf[19]])
|
},
|
||||||
}
|
AddressMode::Extended => MacAddress {
|
||||||
|
extended: [buf[12], buf[13], buf[14], buf[15], buf[16], buf[17], buf[18], buf[19]],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -358,22 +362,26 @@ impl ParseableMacEvent for DataIndication {
|
|||||||
|
|
||||||
let src_addr_mode = AddressMode::try_from(buf[4])?;
|
let src_addr_mode = AddressMode::try_from(buf[4])?;
|
||||||
let src_address = match src_addr_mode {
|
let src_address = match src_addr_mode {
|
||||||
AddressMode::NoAddress => MacAddress::Short([0, 0]),
|
AddressMode::NoAddress => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Reserved => MacAddress::Short([0, 0]),
|
AddressMode::Reserved => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Short => MacAddress::Short([buf[7], buf[8]]),
|
AddressMode::Short => MacAddress {
|
||||||
AddressMode::Extended => {
|
short: [buf[7], buf[8]],
|
||||||
MacAddress::Extended([buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14]])
|
},
|
||||||
}
|
AddressMode::Extended => MacAddress {
|
||||||
|
extended: [buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14]],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let dst_addr_mode = AddressMode::try_from(buf[15])?;
|
let dst_addr_mode = AddressMode::try_from(buf[15])?;
|
||||||
let dst_address = match dst_addr_mode {
|
let dst_address = match dst_addr_mode {
|
||||||
AddressMode::NoAddress => MacAddress::Short([0, 0]),
|
AddressMode::NoAddress => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Reserved => MacAddress::Short([0, 0]),
|
AddressMode::Reserved => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Short => MacAddress::Short([buf[18], buf[19]]),
|
AddressMode::Short => MacAddress {
|
||||||
AddressMode::Extended => {
|
short: [buf[18], buf[19]],
|
||||||
MacAddress::Extended([buf[18], buf[19], buf[20], buf[21], buf[22], buf[23], buf[24], buf[25]])
|
},
|
||||||
}
|
AddressMode::Extended => MacAddress {
|
||||||
|
extended: [buf[18], buf[19], buf[20], buf[21], buf[22], buf[23], buf[24], buf[25]],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -424,12 +432,14 @@ impl ParseableMacEvent for PollIndication {
|
|||||||
|
|
||||||
let addr_mode = AddressMode::try_from(buf[0])?;
|
let addr_mode = AddressMode::try_from(buf[0])?;
|
||||||
let request_address = match addr_mode {
|
let request_address = match addr_mode {
|
||||||
AddressMode::NoAddress => MacAddress::Short([0, 0]),
|
AddressMode::NoAddress => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Reserved => MacAddress::Short([0, 0]),
|
AddressMode::Reserved => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Short => MacAddress::Short([buf[1], buf[2]]),
|
AddressMode::Short => MacAddress {
|
||||||
AddressMode::Extended => {
|
short: [buf[1], buf[2]],
|
||||||
MacAddress::Extended([buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]])
|
},
|
||||||
}
|
AddressMode::Extended => MacAddress {
|
||||||
|
extended: [buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
@ -91,13 +91,15 @@ impl Mac {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_command<T>(&self, cmd: T) -> Result<(), MacError>
|
pub async fn send_command<T>(&self, cmd: &T) -> Result<(), MacError>
|
||||||
where
|
where
|
||||||
T: MacCommand,
|
T: MacCommand,
|
||||||
{
|
{
|
||||||
let mut payload = [0u8; MAX_PACKET_SIZE];
|
let mut payload = [0u8; MAX_PACKET_SIZE];
|
||||||
cmd.copy_into_slice(&mut payload);
|
cmd.copy_into_slice(&mut payload);
|
||||||
|
|
||||||
|
debug!("sending {}", &payload[..T::SIZE]);
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
.tl_write_and_get_response(T::OPCODE as u16, &payload[..T::SIZE])
|
.tl_write_and_get_response(T::OPCODE as u16, &payload[..T::SIZE])
|
||||||
.await;
|
.await;
|
||||||
|
@ -27,6 +27,8 @@ impl ParseableMacEvent for AssociateConfirm {
|
|||||||
const SIZE: usize = 16;
|
const SIZE: usize = 16;
|
||||||
|
|
||||||
fn try_parse(buf: &[u8]) -> Result<Self, ()> {
|
fn try_parse(buf: &[u8]) -> Result<Self, ()> {
|
||||||
|
debug!("{}", buf);
|
||||||
|
|
||||||
Self::validate(buf)?;
|
Self::validate(buf)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -61,12 +63,14 @@ impl ParseableMacEvent for DisassociateConfirm {
|
|||||||
|
|
||||||
let device_addr_mode = AddressMode::try_from(buf[1])?;
|
let device_addr_mode = AddressMode::try_from(buf[1])?;
|
||||||
let device_address = match device_addr_mode {
|
let device_address = match device_addr_mode {
|
||||||
AddressMode::NoAddress => MacAddress::Short([0, 0]),
|
AddressMode::NoAddress => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Reserved => MacAddress::Short([0, 0]),
|
AddressMode::Reserved => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Short => MacAddress::Short([buf[4], buf[5]]),
|
AddressMode::Short => MacAddress {
|
||||||
AddressMode::Extended => {
|
short: [buf[4], buf[5]],
|
||||||
MacAddress::Extended([buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]])
|
},
|
||||||
}
|
AddressMode::Extended => MacAddress {
|
||||||
|
extended: [buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -238,7 +242,6 @@ impl ParseableMacEvent for StartConfirm {
|
|||||||
|
|
||||||
fn try_parse(buf: &[u8]) -> Result<Self, ()> {
|
fn try_parse(buf: &[u8]) -> Result<Self, ()> {
|
||||||
Self::validate(buf)?;
|
Self::validate(buf)?;
|
||||||
debug!("{:#x}", buf);
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
status: MacStatus::try_from(buf[0])?,
|
status: MacStatus::try_from(buf[0])?,
|
||||||
|
@ -109,18 +109,32 @@ numeric_enum! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
pub union MacAddress {
|
||||||
pub enum MacAddress {
|
pub short: [u8; 2],
|
||||||
Short([u8; 2]),
|
pub extended: [u8; 8],
|
||||||
Extended([u8; 8]),
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "defmt")]
|
||||||
|
impl defmt::Format for MacAddress {
|
||||||
|
fn format(&self, fmt: defmt::Formatter) {
|
||||||
|
unsafe {
|
||||||
|
defmt::write!(
|
||||||
|
fmt,
|
||||||
|
"MacAddress {{ short: {}, extended: {} }}",
|
||||||
|
self.short,
|
||||||
|
self.extended
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MacAddress {
|
impl Default for MacAddress {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Short([0, 0])
|
Self { short: [0, 0] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct GtsCharacteristics {
|
pub struct GtsCharacteristics {
|
||||||
pub fields: u8,
|
pub fields: u8,
|
||||||
}
|
}
|
||||||
@ -163,12 +177,14 @@ impl TryFrom<&[u8]> for PanDescriptor {
|
|||||||
|
|
||||||
let coord_addr_mode = AddressMode::try_from(buf[2])?;
|
let coord_addr_mode = AddressMode::try_from(buf[2])?;
|
||||||
let coord_addr = match coord_addr_mode {
|
let coord_addr = match coord_addr_mode {
|
||||||
AddressMode::NoAddress => MacAddress::Short([0, 0]),
|
AddressMode::NoAddress => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Reserved => MacAddress::Short([0, 0]),
|
AddressMode::Reserved => MacAddress { short: [0, 0] },
|
||||||
AddressMode::Short => MacAddress::Short([buf[4], buf[5]]),
|
AddressMode::Short => MacAddress {
|
||||||
AddressMode::Extended => {
|
short: [buf[4], buf[5]],
|
||||||
MacAddress::Extended([buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]])
|
},
|
||||||
}
|
AddressMode::Extended => MacAddress {
|
||||||
|
extended: [buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -255,7 +271,7 @@ defmt::bitflags! {
|
|||||||
|
|
||||||
numeric_enum! {
|
numeric_enum! {
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Default)]
|
#[derive(Default, Clone, Copy)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum KeyIdMode {
|
pub enum KeyIdMode {
|
||||||
#[default]
|
#[default]
|
||||||
@ -285,6 +301,7 @@ numeric_enum! {
|
|||||||
|
|
||||||
numeric_enum! {
|
numeric_enum! {
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum DisassociationReason {
|
pub enum DisassociationReason {
|
||||||
/// The coordinator wishes the device to leave the PAN.
|
/// The coordinator wishes the device to leave the PAN.
|
||||||
@ -296,7 +313,7 @@ numeric_enum! {
|
|||||||
|
|
||||||
numeric_enum! {
|
numeric_enum! {
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Default)]
|
#[derive(Default, Clone, Copy)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum SecurityLevel {
|
pub enum SecurityLevel {
|
||||||
/// MAC Unsecured Mode Security
|
/// MAC Unsecured Mode Security
|
||||||
|
@ -66,7 +66,7 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
info!("resetting");
|
info!("resetting");
|
||||||
mbox.mac_subsystem
|
mbox.mac_subsystem
|
||||||
.send_command(ResetRequest { set_default_pib: true })
|
.send_command(&ResetRequest { set_default_pib: true })
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let evt = mbox.mac_subsystem.read().await;
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
@ -75,7 +75,7 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("setting extended address");
|
info!("setting extended address");
|
||||||
let extended_address: u64 = 0xACDE480000000001;
|
let extended_address: u64 = 0xACDE480000000001;
|
||||||
mbox.mac_subsystem
|
mbox.mac_subsystem
|
||||||
.send_command(SetRequest {
|
.send_command(&SetRequest {
|
||||||
pib_attribute_ptr: &extended_address as *const _ as *const u8,
|
pib_attribute_ptr: &extended_address as *const _ as *const u8,
|
||||||
pib_attribute: PibId::ExtendedAddress,
|
pib_attribute: PibId::ExtendedAddress,
|
||||||
})
|
})
|
||||||
@ -87,7 +87,7 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("setting short address");
|
info!("setting short address");
|
||||||
let short_address: u16 = 0x1122;
|
let short_address: u16 = 0x1122;
|
||||||
mbox.mac_subsystem
|
mbox.mac_subsystem
|
||||||
.send_command(SetRequest {
|
.send_command(&SetRequest {
|
||||||
pib_attribute_ptr: &short_address as *const _ as *const u8,
|
pib_attribute_ptr: &short_address as *const _ as *const u8,
|
||||||
pib_attribute: PibId::ShortAddress,
|
pib_attribute: PibId::ShortAddress,
|
||||||
})
|
})
|
||||||
@ -99,7 +99,7 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("setting association permit");
|
info!("setting association permit");
|
||||||
let association_permit: bool = true;
|
let association_permit: bool = true;
|
||||||
mbox.mac_subsystem
|
mbox.mac_subsystem
|
||||||
.send_command(SetRequest {
|
.send_command(&SetRequest {
|
||||||
pib_attribute_ptr: &association_permit as *const _ as *const u8,
|
pib_attribute_ptr: &association_permit as *const _ as *const u8,
|
||||||
pib_attribute: PibId::AssociationPermit,
|
pib_attribute: PibId::AssociationPermit,
|
||||||
})
|
})
|
||||||
@ -111,7 +111,7 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("setting TX power");
|
info!("setting TX power");
|
||||||
let transmit_power: i8 = 2;
|
let transmit_power: i8 = 2;
|
||||||
mbox.mac_subsystem
|
mbox.mac_subsystem
|
||||||
.send_command(SetRequest {
|
.send_command(&SetRequest {
|
||||||
pib_attribute_ptr: &transmit_power as *const _ as *const u8,
|
pib_attribute_ptr: &transmit_power as *const _ as *const u8,
|
||||||
pib_attribute: PibId::TransmitPower,
|
pib_attribute: PibId::TransmitPower,
|
||||||
})
|
})
|
||||||
@ -122,7 +122,8 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
info!("starting FFD device");
|
info!("starting FFD device");
|
||||||
mbox.mac_subsystem
|
mbox.mac_subsystem
|
||||||
.send_command(StartRequest {
|
.send_command(&StartRequest {
|
||||||
|
pan_id: [0xAA, 0x1A],
|
||||||
channel_number: MacChannel::Channel16,
|
channel_number: MacChannel::Channel16,
|
||||||
beacon_order: 0x0F,
|
beacon_order: 0x0F,
|
||||||
superframe_order: 0x0F,
|
superframe_order: 0x0F,
|
||||||
@ -138,7 +139,7 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("setting RX on when idle");
|
info!("setting RX on when idle");
|
||||||
let rx_on_while_idle: bool = true;
|
let rx_on_while_idle: bool = true;
|
||||||
mbox.mac_subsystem
|
mbox.mac_subsystem
|
||||||
.send_command(SetRequest {
|
.send_command(&SetRequest {
|
||||||
pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
|
pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
|
||||||
pib_attribute: PibId::RxOnWhenIdle,
|
pib_attribute: PibId::RxOnWhenIdle,
|
||||||
})
|
})
|
||||||
@ -151,7 +152,4 @@ async fn main(spawner: Spawner) {
|
|||||||
let evt = mbox.mac_subsystem.read().await;
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
defmt::info!("{:#x}", evt);
|
defmt::info!("{:#x}", evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Test OK");
|
|
||||||
cortex_m::asm::bkpt();
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@ use defmt::*;
|
|||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::bind_interrupts;
|
use embassy_stm32::bind_interrupts;
|
||||||
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
|
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
|
||||||
use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, ResetRequest, SetRequest, StartRequest};
|
use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest};
|
||||||
|
use embassy_stm32_wpan::sub::mac::event::MacEvent;
|
||||||
use embassy_stm32_wpan::sub::mac::typedefs::{
|
use embassy_stm32_wpan::sub::mac::typedefs::{
|
||||||
AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PibId, SecurityLevel,
|
AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PibId, SecurityLevel,
|
||||||
};
|
};
|
||||||
@ -67,52 +68,75 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("initialized mac: {}", result);
|
info!("initialized mac: {}", result);
|
||||||
|
|
||||||
info!("resetting");
|
info!("resetting");
|
||||||
let response = mbox
|
mbox.mac_subsystem
|
||||||
.mac_subsystem
|
.send_command(&ResetRequest { set_default_pib: true })
|
||||||
.send_command(ResetRequest { set_default_pib: true })
|
.await
|
||||||
.await;
|
.unwrap();
|
||||||
info!("{}", response);
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
|
info!("{:#x}", evt);
|
||||||
|
|
||||||
info!("setting extended address");
|
info!("setting extended address");
|
||||||
let extended_address: u64 = 0xACDE480000000002;
|
let extended_address: u64 = 0xACDE480000000002;
|
||||||
let response = mbox
|
mbox.mac_subsystem
|
||||||
.mac_subsystem
|
.send_command(&SetRequest {
|
||||||
.send_command(SetRequest {
|
|
||||||
pib_attribute_ptr: &extended_address as *const _ as *const u8,
|
pib_attribute_ptr: &extended_address as *const _ as *const u8,
|
||||||
pib_attribute: PibId::ExtendedAddress,
|
pib_attribute: PibId::ExtendedAddress,
|
||||||
})
|
})
|
||||||
.await;
|
.await
|
||||||
info!("{}", response);
|
.unwrap();
|
||||||
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
|
info!("{:#x}", evt);
|
||||||
|
|
||||||
|
info!("getting extended address");
|
||||||
|
mbox.mac_subsystem
|
||||||
|
.send_command(&GetRequest {
|
||||||
|
pib_attribute: PibId::ExtendedAddress,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
|
info!("{:#x}", evt);
|
||||||
|
|
||||||
|
if let Ok(MacEvent::MlmeGetCnf(evt)) = evt {
|
||||||
|
if evt.pib_attribute_value_len == 8 {
|
||||||
|
let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
|
||||||
|
|
||||||
|
info!("value {:#x}", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
info!("assocation request");
|
info!("assocation request");
|
||||||
let response = mbox
|
let a = AssociateRequest {
|
||||||
.mac_subsystem
|
channel_number: MacChannel::Channel16,
|
||||||
.send_command(AssociateRequest {
|
channel_page: 0,
|
||||||
channel_number: MacChannel::Channel16,
|
coord_addr_mode: AddressMode::Short,
|
||||||
channel_page: 0,
|
coord_address: MacAddress { short: [34, 17] },
|
||||||
coord_addr_mode: AddressMode::Short,
|
capability_information: Capabilities::ALLOCATE_ADDRESS,
|
||||||
coord_address: MacAddress::Short([0x22, 0x11]),
|
coord_pan_id: [0xAA, 0x1A],
|
||||||
capability_information: Capabilities::ALLOCATE_ADDRESS,
|
security_level: SecurityLevel::Unsecure,
|
||||||
coord_pan_id: [0xAA, 0x1A],
|
key_id_mode: KeyIdMode::Implicite,
|
||||||
security_level: SecurityLevel::Unsecure,
|
key_source: [0; 8],
|
||||||
key_id_mode: KeyIdMode::Implicite,
|
key_index: 152,
|
||||||
key_source: [0; 8],
|
};
|
||||||
key_index: 0,
|
info!("{}", a);
|
||||||
})
|
mbox.mac_subsystem.send_command(&a).await.unwrap();
|
||||||
.await;
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
info!("{}", response);
|
info!("{:#x}", evt);
|
||||||
|
|
||||||
info!("setting short address");
|
info!("setting short address");
|
||||||
let short: u64 = 0xACDE480000000002;
|
let short: u64 = 0xACDE480000000002;
|
||||||
let response = mbox
|
mbox.mac_subsystem
|
||||||
.mac_subsystem
|
.send_command(&SetRequest {
|
||||||
.send_command(SetRequest {
|
|
||||||
pib_attribute_ptr: &short as *const _ as *const u8,
|
pib_attribute_ptr: &short as *const _ as *const u8,
|
||||||
pib_attribute: PibId::ShortAddress,
|
pib_attribute: PibId::ShortAddress,
|
||||||
})
|
})
|
||||||
.await;
|
.await
|
||||||
info!("{}", response);
|
.unwrap();
|
||||||
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
|
info!("{:#x}", evt);
|
||||||
|
|
||||||
info!("Test OK");
|
loop {
|
||||||
cortex_m::asm::bkpt();
|
let evt = mbox.mac_subsystem.read().await;
|
||||||
|
info!("{:#x}", evt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user