ieee802154.rs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. use super::*;
  2. impl InterfaceInner {
  3. pub(super) fn process_ieee802154<'output, 'payload: 'output>(
  4. &mut self,
  5. sockets: &mut SocketSet,
  6. meta: PacketMeta,
  7. sixlowpan_payload: &'payload [u8],
  8. _fragments: &'output mut FragmentsBuffer,
  9. ) -> Option<Packet<'output>> {
  10. let ieee802154_frame = check!(Ieee802154Frame::new_checked(sixlowpan_payload));
  11. if ieee802154_frame.frame_type() != Ieee802154FrameType::Data {
  12. return None;
  13. }
  14. let ieee802154_repr = check!(Ieee802154Repr::parse(&ieee802154_frame));
  15. // Drop frames when the user has set a PAN id and the PAN id from frame is not equal to this
  16. // When the user didn't set a PAN id (so it is None), then we accept all PAN id's.
  17. // We always accept the broadcast PAN id.
  18. if self.pan_id.is_some()
  19. && ieee802154_repr.dst_pan_id != self.pan_id
  20. && ieee802154_repr.dst_pan_id != Some(Ieee802154Pan::BROADCAST)
  21. {
  22. net_debug!(
  23. "IEEE802.15.4: dropping {:?} because not our PAN id (or not broadcast)",
  24. ieee802154_repr
  25. );
  26. return None;
  27. }
  28. match ieee802154_frame.payload() {
  29. Some(payload) => {
  30. self.process_sixlowpan(sockets, meta, &ieee802154_repr, payload, _fragments)
  31. }
  32. None => None,
  33. }
  34. }
  35. pub(super) fn dispatch_ieee802154<Tx: TxToken>(
  36. &mut self,
  37. ll_dst_a: Ieee802154Address,
  38. tx_token: Tx,
  39. meta: PacketMeta,
  40. packet: Packet,
  41. frag: &mut Fragmenter,
  42. ) {
  43. let ll_src_a = self.hardware_addr.ieee802154_or_panic();
  44. // Create the IEEE802.15.4 header.
  45. let ieee_repr = Ieee802154Repr {
  46. frame_type: Ieee802154FrameType::Data,
  47. security_enabled: false,
  48. frame_pending: false,
  49. ack_request: false,
  50. sequence_number: Some(self.get_sequence_number()),
  51. pan_id_compression: true,
  52. frame_version: Ieee802154FrameVersion::Ieee802154_2003,
  53. dst_pan_id: self.pan_id,
  54. dst_addr: Some(ll_dst_a),
  55. src_pan_id: self.pan_id,
  56. src_addr: Some(ll_src_a),
  57. };
  58. self.dispatch_sixlowpan(tx_token, meta, packet, ieee_repr, frag);
  59. }
  60. #[cfg(feature = "proto-sixlowpan-fragmentation")]
  61. pub(super) fn dispatch_ieee802154_frag<Tx: TxToken>(
  62. &mut self,
  63. tx_token: Tx,
  64. frag: &mut Fragmenter,
  65. ) {
  66. // Create the IEEE802.15.4 header.
  67. let ieee_repr = Ieee802154Repr {
  68. frame_type: Ieee802154FrameType::Data,
  69. security_enabled: false,
  70. frame_pending: false,
  71. ack_request: false,
  72. sequence_number: Some(self.get_sequence_number()),
  73. pan_id_compression: true,
  74. frame_version: Ieee802154FrameVersion::Ieee802154_2003,
  75. dst_pan_id: self.pan_id,
  76. dst_addr: Some(frag.sixlowpan.ll_dst_addr),
  77. src_pan_id: self.pan_id,
  78. src_addr: Some(frag.sixlowpan.ll_src_addr),
  79. };
  80. self.dispatch_sixlowpan_frag(tx_token, ieee_repr, frag);
  81. }
  82. }