ComputeJoinAcceptMIC computes the Message Integrity Code for a join-accept message - The payload contains MHDR | JoinNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) - the joinReqType is 0xFF in reply to a join-request or the rejoin type in reply to a RejoinRequest
(jsIntKey types.AES128Key, joinReqType byte, joinEUI types.EUI64, dn types.DevNonce, payload []byte)
| 151 | // - The payload contains MHDR | JoinNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) |
| 152 | // - the joinReqType is 0xFF in reply to a join-request or the rejoin type in reply to a RejoinRequest |
| 153 | func ComputeJoinAcceptMIC(jsIntKey types.AES128Key, joinReqType byte, joinEUI types.EUI64, dn types.DevNonce, payload []byte) ([4]byte, error) { |
| 154 | if n := len(payload); n != 13 && n != 29 { |
| 155 | return [4]byte{}, errInvalidJoinAcceptPayloadSize.WithAttributes("size", len(payload)) |
| 156 | } |
| 157 | hash, err := cmac.New(jsIntKey[:]) |
| 158 | if err != nil { |
| 159 | return [4]byte{}, err |
| 160 | } |
| 161 | _, err = hash.Write(append(append([]byte{joinReqType}, reverse(joinEUI[:])...), reverse(dn[:])...)) |
| 162 | if err != nil { |
| 163 | return [4]byte{}, err |
| 164 | } |
| 165 | _, err = hash.Write(payload) |
| 166 | if err != nil { |
| 167 | return [4]byte{}, err |
| 168 | } |
| 169 | var mic [4]byte |
| 170 | copy(mic[:], hash.Sum([]byte{})) |
| 171 | return mic, nil |
| 172 | } |