X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/e67ea96c8a3d7c23ba29c6ed91ddb451927176a1..9e40113187a3eb54335de0277f8038ee35d9428a:/m17core/src/protocol.rs diff --git a/m17core/src/protocol.rs b/m17core/src/protocol.rs index 96def5b..375c3f0 100755 --- a/m17core/src/protocol.rs +++ b/m17core/src/protocol.rs @@ -33,6 +33,7 @@ pub enum Frame { // BERT } +#[derive(Debug, Clone, PartialEq, Eq)] pub enum PacketType { /// RAW Raw, @@ -53,6 +54,22 @@ pub enum PacketType { } impl PacketType { + pub fn from_proto(buf: &[u8]) -> Option<(Self, usize)> { + buf.utf8_chunks() + .next() + .and_then(|chunk| chunk.valid().chars().next()) + .map(|c| match c as u32 { + 0x00 => (PacketType::Raw, 1), + 0x01 => (PacketType::Ax25, 1), + 0x02 => (PacketType::Aprs, 1), + 0x03 => (PacketType::SixLowPan, 1), + 0x04 => (PacketType::Ipv4, 1), + 0x05 => (PacketType::Sms, 1), + 0x06 => (PacketType::Winlink, 1), + _ => (PacketType::Other(c), c.len_utf8()), + }) + } + pub fn as_proto(&self) -> ([u8; 4], usize) { match self { PacketType::Raw => ([0, 0, 0, 0], 1), @@ -70,22 +87,6 @@ impl PacketType { } } } - - pub fn from_proto(&self, buf: &[u8]) -> Option { - buf.utf8_chunks() - .next() - .and_then(|chunk| chunk.valid().chars().next()) - .map(|c| match c as u32 { - 0x00 => PacketType::Raw, - 0x01 => PacketType::Ax25, - 0x02 => PacketType::Aprs, - 0x03 => PacketType::SixLowPan, - 0x04 => PacketType::Ipv4, - 0x05 => PacketType::Sms, - 0x06 => PacketType::Winlink, - _ => PacketType::Other(c), - }) - } } #[derive(Debug, Clone, PartialEq, Eq)] @@ -132,6 +133,8 @@ impl LsfFrame { } } + // TODO: encryption sub-type + pub fn channel_access_number(&self) -> u8 { (self.0[12] >> 7) & 0x0f }