ComputeRejoinRequestMIC computes the Message Integrity Code for a RejoinRequest message - For a type 0 or 2 RejoinRequest, the payload contains MHDR | RejoinType | NetID | DevEUI | RJcount0 - For a type 0 or 2 RejoinRequest, the SNwkSIntKey is used - For a type 1 RejoinRequest, the payload contains
(key types.AES128Key, payload []byte)
| 97 | // - For a type 1 RejoinRequest, the payload contains MHDR | RejoinType | JoinEUI | DevEUI | RJcount1 |
| 98 | // - For a type 1 RejoinRequest, the JSIntKey is used |
| 99 | func ComputeRejoinRequestMIC(key types.AES128Key, payload []byte) ([4]byte, error) { |
| 100 | if len(payload) != 15 && len(payload) != 20 { |
| 101 | return [4]byte{}, errrInvalidRejoinRequestSize.WithAttributes("size", len(payload)) |
| 102 | } |
| 103 | rejoinType := payload[1] |
| 104 | switch rejoinType { |
| 105 | case 0, 2: |
| 106 | if len(payload) != 15 { |
| 107 | return [4]byte{}, errrInvalidRejoinRequestType0_2.WithAttributes("size", len(payload)) |
| 108 | } |
| 109 | case 1: |
| 110 | if len(payload) != 20 { |
| 111 | return [4]byte{}, errrInvalidRejoinRequestType1.WithAttributes("size", len(payload)) |
| 112 | } |
| 113 | } |
| 114 | hash, err := cmac.New(key[:]) |
| 115 | if err != nil { |
| 116 | return [4]byte{}, err |
| 117 | } |
| 118 | _, err = hash.Write(payload) |
| 119 | if err != nil { |
| 120 | return [4]byte{}, err |
| 121 | } |
| 122 | var mic [4]byte |
| 123 | copy(mic[:], hash.Sum([]byte{})) |
| 124 | return mic, nil |
| 125 | } |
| 126 | |
| 127 | var errInvalidJoinAcceptPayloadSize = errInvalidSize("join_accept_payload", "JoinAccept payload", "13 or 29") |
| 128 |