Skip to content

Commit

Permalink
solution proposal for #42: discard slac_match confirmation if the des…
Browse files Browse the repository at this point in the history
…tination MAC does not match
  • Loading branch information
uhi22 committed Oct 15, 2024
1 parent 7a6c6d5 commit c76baef
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions ccs/homeplug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ static void composeSlacMatchReq(void)
static void evaluateSlacMatchCnf(void)
{
uint8_t i;
uint8_t blIsDestinationMacForMe;
// The SLAC_MATCH.CNF contains the NMK and the NID.
// We extract this information, so that we can use it for the CM_SET_KEY afterwards.
// References: https://github.com/qca/open-plc-utils/blob/master/slac/evse_cm_slac_match.c
Expand All @@ -358,25 +359,36 @@ static void evaluateSlacMatchCnf(void)
}
else
{
addToTrace(MOD_HOMEPLUG, "[PEVSLAC] received SLAC_MATCH.CNF");
for (i=0; i<7; i++) // NID has 7 bytes
{
NID[i] = myethreceivebuffer[85+i];
}
for (i=0; i<16; i++)
{
NMK[i] = myethreceivebuffer[93+i];
blIsDestinationMacForMe = 1;
for (i=0; i<6; i++) {
/* compare all 6 bytes of the destination MAC with our own MAC */
if (myethreceivebuffer[i] != myMAC[i]) {
blIsDestinationMacForMe = 0; /* any mismatch -> it is not for me */
}
}
addToTrace(MOD_HOMEPLUG, "[PEVSLAC] From SlacMatchCnf, got network membership key (NMK) and NID.");
// use the extracted NMK and NID to set the key in the adaptor:
composeSetKey();
addToTrace(MOD_HOMEPLUG, "[PEVSLAC] Checkpoint170: transmitting CM_SET_KEY.REQ");
setCheckpoint(170);
publishStatus("SLAC", "set key");
myEthTransmit();
if (pevSequenceState==STATE_WAITING_FOR_SLAC_MATCH_CNF) // we were waiting for finishing the SLAC_MATCH.CNF and SET_KEY.REQ
{
slac_enterState(STATE_WAITING_FOR_RESTART2);
if (!blIsDestinationMacForMe) {
addToTrace(MOD_HOMEPLUG, "[PEVSLAC] received SLAC_MATCH.CNF but with foreign destination MAC. Ignoring.");
} else {
addToTrace(MOD_HOMEPLUG, "[PEVSLAC] received SLAC_MATCH.CNF");
for (i=0; i<7; i++) // NID has 7 bytes
{
NID[i] = myethreceivebuffer[85+i];
}
for (i=0; i<16; i++)
{
NMK[i] = myethreceivebuffer[93+i];
}
addToTrace(MOD_HOMEPLUG, "[PEVSLAC] From SlacMatchCnf, got network membership key (NMK) and NID.");
// use the extracted NMK and NID to set the key in the adaptor:
composeSetKey();
addToTrace(MOD_HOMEPLUG, "[PEVSLAC] Checkpoint170: transmitting CM_SET_KEY.REQ");
setCheckpoint(170);
publishStatus("SLAC", "set key");
myEthTransmit();
if (pevSequenceState==STATE_WAITING_FOR_SLAC_MATCH_CNF) // we were waiting for finishing the SLAC_MATCH.CNF and SET_KEY.REQ
{
slac_enterState(STATE_WAITING_FOR_RESTART2);
}
}
}
}
Expand Down

0 comments on commit c76baef

Please sign in to comment.