# SLAC Functions and Variables

The functions described in this chapter implement SLAC protocol building blocks. Essentially, there is one function for each dataflow shown on the SLAC interface diagram. The implementations are not sophisticated. Customers must adapt them their own run-time environments.

To assist in adapting functions fo various environments, SLAC functions all accept three arguments. The first is a session variable that references information that supports a single PEV-EVSE SLAC interaction. The second is a channel variable that references information that supports ISO Layer 2 network communications. The third is a message variable that references an IEEE 802.3 frame buffer used to format, transmit, receive and interpret SLAC messages. Applications may create lists, stacks, queues or heaps of session variables to support multiple PEV-EVSE conversations. That has not been done here but may be done in the future.

PEV-HLE determines the application type and security type and stores them in the session variable before attempting a new SLAC session. PEV-HLE also generates and stores the run identifier in the session variable before attempting a new SLAC session. The run identifier is included in messages so that the EVSE-HLE can distinguish frames from different PEV-HLEs when transmitted in broadcast.

## The Session Variable

The session variable is a structure defined in slac.h. It stores the information needed to manage a single SLAC protocol session between PEV-HLE and EVSE-HLE. It is necessary because there are cases where multiple PEV-HLE attempt to communicate with one EVSE-HLE or vice verse and each communication involves multiple steps and some steps will fail or be abandoned.

session.RunID

  A session identifier used to support multiple PEV-EVSE sessions. The PEV-HLE defines a new value with each associateion attempt and broadcasts it to EVSE-HLE in `CM_SLAC_PARAM.REQ` `RunID`. EVSE-HLE receive it and store it in their session variable. Once association starts, subsequent messages, in both directions, include this identifier so that PEV-HLE and EVSE-HLE can detect and collate messages from the same conversation.

session.APPLICATION_TYPE

  Indicates the context in which the SLAC process is being carried out. Currently, the only context is PEV-EVSE association. The PEV-HLE sends this value to the EVSE-HLE in EVSE-HLE in `CM_SLAC_PARAM.REQ` message `APPLICATION_TYPE` field. EVSE-HLE receive it and store it in their session variable.

session.SECURITY_TYPE

  Indicates that the sender prefers Secure SLAC for PEV-EVSE matching. Currently, the only value used in SLAC demonstration software is `0` for No Security. The PEV-HLE defines this value as `0` on startup and broadcasts it to EVSE-HLE in in `CM_SLAC_PARAM.REQ` message `SECURITY_TYPE` field. EVSE-HLE receive it and store it in their session variable for later use when sending SLAC messages.

session.RESP_TYPE

  The EVSE-HLE defines this value and sends it to the PEV-HLE in `CM_SLAC_PARAM.CNF` message `RESP_TYPE` field. THe default is `0` but this can be changed using response type = in profile `evse.ini`.

session.NUM_SOUNDS

  The number of `CM_MNBC_SOUND.IND` messages that the PEV-HLE should send during sounding. The EVSE-HLE defines this value and sends it to PEV-HLE in `CM_SLAC_PARAM.CNF` message `NUM_SOUNDS` field. The default is `10` but this can be changed using time to soundi = in profile `evse.ini`.

session.TIME_OUT

  The total time allowed for all session sounding to complete. Any msounds arriving after the timeout will be lost. The time is expressed in 100 msec increments. The EVSE-HLE defines this value and sends it to PEV_HLE in `CM_SLAC_PARAM.CNF`. The default is `8` but this can be changed using number of sounds = in profile `evse.ini`.

session.AAG []

  The cumulative average attenuation across `58` groups of `16` carriers. The EVSE-HLE computes these averages from multiple `CM_ATTEN_PROFILE.IND` and forwards them to PEV-HLE in `CM_ATTEN_CHAR.IND`. PEV_HLE populates array from `CM_ATTEN_CHAR.IND` message `ACVarField.ATTEN_PROFILE.AAG` field and evaluates it by averaging all values in the array to determine the overall average attenuation. If that values is less than or equal to session.limit then a match may be attempted.

session.NumGroups

  The number of elements in array session.AAG. This EVSE-HLE defines this number and sends it to PEV-HLE in `CM_ATTEN_CHAR.IND` `ACVarField.NumGroups`. For practical purposes, this value of this variable is constant at `58`.

session.MSOUND_TARGET

  MAC address of EVSE-HLE that will receive `CM_MNBC_SOUND.IND` messages. The EVSE-HLE defines this address and broadcasts it to PEV-HLE in `CM_SLAC_PARAM.CNF` message `M-SOUND_TRAGET` field. THe PEV-HLE stores this address in its session variable. The default is `FF:FF:FF:FF:FF:FF` and remains constant. This value is not used at this time.

session.FORWARDING_STA

  MAC address of PEV-HLE to receive `CM_SLAC_PROFILE.IND` messages. The EVSE-HLE defines this address and sends it to PEV-HLE in `CM_SLAC_PARAM.CNF` message `FORWARDING_STA` field. THe PEV-HLE stores this address in its session variable. The default is `FF:FF:FF:FF:FF:FF` and remains constant. This value is ignored when RESP_TYPE=0.

session.PEV_ID

  The vehicle identification number. The PEV-HLE sends this value to the EVSE-HLE in `CM_SLAC_MATCH.REQ` `MatchVarField.PEV_ID` field. The default is `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA` but is can be changed using vehicle identifier = in profile `pev.ini`. The MatchVarField portion of the message forms the transaction record and may be encrypted.

session.PEV_MAC

  PEV-HLE MAC address. The PEV-HLE sends this address to the EVSE-HLE in `CM_SLAC_MATCH.REQ` `MatchVarField.PEV_MAC` field. The MatchVarField portion of the message forms the transaction record and may be encrypted.

session.EVSE_ID

  The station identification number. The EVSE-HLE sends this value to PEV-HLE in `CM_SLAC_MATCH.CNF` message `MatchVarField.EVSE_ID` field. The default is `BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB` but is can be changed using station identifier = in profile `evse.ini`. The MatchVarField portion of the message forms the transaction record and may be encrypted.

session.EVSE_MAC

  EVSE-HLE MAC address. The EVSE-HLE sends this value to PEV-HLE in `CM_SLAC_MATCH.CNF` message `MatchVarField.EVSE_MAC` field. The MatchVarField portion of the message forms the transaction record and may be encrypted.

session.NMK

  The EVSE-PLC Network Membership Key. The EVSE-HLE defines this value when the station powers on. The EVSE-HLE sends the NMK to the PEV-HLE in `CM_SLAC_MATCH.CNF` message `MatchField.NMK` field. The PEV-HLE uses this value to form a network with the EVSE-PLC during charging. The MatchVarField portion of the message forms the transaction record and may be encrypted.

  The default for PEV-HLE is `50D3E4933F855B7040784DF815AA8DB7`, which is the key derived from network password HomePlugAV, but that can be changed using nwtwork membership key = in profile `pev.ini`.

  The default for EVSE-HLE is `B59319D7E8157BA001B018669CCEE30D`, which is the key derived from network password HomePlugAV0123, but that can be changed using nwtwork membership key = in profile `evse.ini`.

session.NID

  The EVSE-PLC Network Identifier. The EVSE-HLE defines this value when the station powers. The EVSE-HLE sends the NID to the PEV-HLE in `CM_SLAC_MATCH.CNF` message `MatchField.NID` field. The PEV-HLE uses this value to form a network with the EVSE-PLC during charging. The MatchVarField portion of the message forms the transaction record and may be encrypted.

  The default for PEV-HLE is `B0F2E695666B03`, which is the key derived from network password HomePlugAV, but that can be changed using nwtwork membership key = in profile `pev.ini`.

  The default for EVSE-HLE is `026BCBA5354E08`, which is the key derived from network password HomePlugAV0123, but that can be changed using nwtwork membership key = in profile `evse.ini`.

session.RND

  A random value. PEV-HLE computes this value and sends it to EVSE-HLE in `CM_MNBC_SOUND.IND`. This value is not used at this time.

session.original_nmk

  The original PEV-PLC Network Membership Key. This is the original NMK of the PEV-HLE. The PEV-HLE preserves this value before, and restores it after, the charging cycle. The Qualcomm Atheros PEV-HLE and EVSE-HLE demonstration software reads these values from profile `pev.ini` and `evse.ini`, respectively, by network membership key = .

session.original_nid

  The PLC Network Identifier (NID). PEV-PLC and EVSE-PLC will each have a different NID at the start of the SLAC process. This value must be preserved before, and restored after, charging. Once charging is complete, PEV-HLE and EVSE-HLE restore this value to their respective PLC using `CM_SET_KEY`. In a real world implementation, PEV-HLE and EVSE-HLE would read this value from their repective PLC and save it in session.nmk and session.NMK. The Qualcomm Atheros PEV-HLE and EVSE-HLE demonstration software reads these values from profile `pev.ini` and `evse.ini`, respectively, by network identifier = .

session.state

  The current SLAC protocol session state. Qualcomm Atheros PEV-HLE and EVSE-HLE demonstration programs use this value to direct internal state transitions. Values range from `0` through `3`.

session.sounds

  The number of MSounds captured received by EVSE-HLE. This value may be less that NUM_SOUNDS the requested by the EVSE_HLE due to network interruptions or EVSE-HLE overloading. This is the denominator used when computing the average attenuation in array session.AAG. The values is set by PEV_HLE from `CM_ATTEN_CHAR.IND` message `NUM_SOUNDS` field.

session.limit

  The attenuation threshold. If the average attenuation value in session.AAG exceeds this value the PEV-HLE will make no attempt to connect the PEV-PLC to the EVSE-PLC. The default value is `10` but this can be re-defined in profile `pev.ini` by attenuation threshold = .

session.pause

  The time in milliseconds between MSounds. Sounding too frequently does not allow enough time for the EVSE-PLC to sample and compute values. Sounding too infrequently wastes time. The maximum sample rate may be limited by the quality of the powerline media and traffic passwing through the EVSE-PLC. The default is `10` but can be re-defined in profile `pev.ini` by msound pause = .

session.chargetime

  The time in milliseconds allowed for the charging cycle to complete. The default is `10` but this can be changed using charge time = in profile `pev.ini` and `evse.ini`. The charge time should be the same for PEV-HLE and EVSE-HLE when running long tests.

session.settletime

  The time in milliseconds allowed for the charging cycle to complete. The default is `10` but this can be changed using settle time = in profile `pev.ini` and `evse.ini`. The settle time should be the same for PEV-HLE and EVSE-HLE when running long tests.

session.counter

  The number of chaging session that have take place. This variable is not part of the SLAC protocol. The PEV-HLE and EVSE-HLE increment this counter each time they enter the Charging state and exchange this value in the unused `CM_SLAC_PARAM.REW` and `CM_SLAC_PARAM.CNF` message `CipherSuite` field. Runtime options can be used to instruct either the PEV-HLE or EVSE-HLE to terminate if their counts are out-of-sync.

session.flags

  A bit-mapped flagword used to control program flow based on user-specified command line options.

## pev_cm_slac_param

      				signed pev_cm_slac_param
       				struct session * session
       				struct channel * channel
       				struct message * message

PEV-HLE broadcasts `CM_SLAC_PARAM.REQ` messages and waits for a `CM_SLAC_PARAM.CNF` from EVSE-HLEs. This is the first message sent and it initiates SLAC session one some EVSE-HLE responds. Function pev_cm_slac_param copies session.APPLICATION_TYPE, session.SECURITY_TYPE and session.RunID into `CM_SLAC_PARAM.REQ` and broadcasts it to listening EVSE-HLE.

It is possible that multiple EVSE-HLEs will respond but one response is sufficient to proceed. If a `CM_SLAC_PARAM.CNF` is not received within a reasonable time, PEV-HLE sends another another `CM_SLAC_PARAM.REQ` message. PEV-HLE should compare the run identifier in the `CM_SLAC_PARAM.CNF` to that stored in the session variable to ensure that it is not processing `CM_SLAC_PARAM.CNF` messages from some other session. PEV-HLE compares `RunID`, `APPLICATION_TYPE` and `SECURITY_TYPE` from `CM_SLAC_PARAM.CNF` to that stored in the session variable to ensure they have not changed. PEV-HLE stores `MSOUND_TARGET`, `NUM_SOUNDS` and `TIME_OUT` in the session variable for later use.

## evse_cm_slac_param

      				signed evse_cm_slac_param
       				struct session * session
       				struct channel * channel
       				struct message * message

EVSE-HLE receives a `CM_SLAC_PARAM.REQ` and responds with a `CM_SLAC_PARAM.CNF` message. This function waits indefinitly for `CM_SLAC_PARAM.REQ` then copies `RunID`, `APPLICATION_TYPE` and `SECURITY_TYPE` from `CM_SLAC_PARAM.REQ` to the session variable for later use. It then copies session.MSOUND_TARGET, session.NUM_SOUNDS, session.TIME_OUT, session.RESP_TYPE, session.FORWARDING_STA, session.APPLICATION_TYPE, session.SECURITY_TYPE and session.RunID to `CM_SLAC_PARAM.CNF` and sends it unicast to the requesting PEV-HLE.

## pev_cm_start_atten_char

      				signed evse_cm_start_atten_char
       				struct session * session
       				struct channel * channel
       				struct message * message

PEV-HLE informs listening EVSE-HLE that sounding is about to start by broadcasting `CM_START_ATTEN_CHAR.IND`. Function pev_cm_start_char copies session.NUM_SOUNDS, session.TIME_OUT, session.RESP_TYPE, session.FORWARDING_STA and session.RunID to `CM_START_ATTEN_CHAR.IND`.

The standard recommends that this message be sent three times. Our demonstration software does not do this.

## evse_cm_start_atten_char

      				signed evse_cm_start_atten_char
       				struct session * session
       				struct channel * channel
       				struct message * message

EVSE-HLE receives `CM_START_ATTEN_CHAR` from PEV-HLE and prepares to receive sounds by initializing msound counters and starting a timer. This function compares `RunID` from `CM_START_ATTEN_CHAR` to session.RunID to ensure that this message belongs to a known session. This function compares `APPLICATION_TYPE`, `SECURITY_TYPE`, `NUM_SOUNDS`, `TIME_OUT`, `RESP_TYPE` and `FORWARDING_STA` to the session variable to ensure that values have not changed.

## pev_cm_mnbc_sound

      				signed pev_cm_mnbc_sound
       				struct session * session
       				struct channel * channel
       				struct message * message

PEV-HLE sends periodic `CM_MNBC_SOUND.IND` to EVSE-HLE.

## evse_cm_mnbc_sound

      				signed evse_cm_mnbc_sound
       				struct session * session
       				struct channel * channel
       				struct message * message

EVSE-HLE receives interleaved `CM_MNBC_SOUND.IND` from PEV-HLE and `CM_ATTEN_PROFILE.IND` messages from EVSE-PLC. This function maintains a running average of attenuation values across each carrier group in array session.AAG.

## evse_cm_atten_char

      				signed evse_cm_atten_char
       				struct session * session
       				struct channel * channel
       				struct message * message

EVSE-HLE sends `CM_ATTEN_CHAR.IND` to PEV-HLE. This function copies session.AAG to `CM_ATTEN_CHAR.IND`.

## pev_cm_atten_char

      				signed pev_cm_atten_char
       				struct session * session
       				struct channel * channel
       				struct message * message

PEV-HLE receives `CM_ATTEN_CHAR.IND` from EVSE-HLE and acknwoledges with `CM_ATTEN_CHAR.RSP`.

## pev_cm_slac_match

      				signed pev_cm_slac_match
       				struct session * session
       				struct channel * channel
       				struct message * message

PEV-HLE sends `CM_SLAC_MATCH.REQ` to selected EVSE-HLE and waits for `CM_SLAC_MATCH.CNF`. This function evaluates sounds across all carrier groups and compares result to some threshold and selects one EVSE-HLE. This function copies session.APPLICAION_TYPE, session.SECURITY_TYPE, session.PEV_ID, session.PEV_MAC and session.RunID to `CM_SLAC_PARAM.REQ` and sends it unicast to the selected EVSE-HLE.

## evse_cm_slac_match

      				signed evse_cm_slac_match
       				struct session * session
       				struct channel * channel
       				struct message * message

EVSE-HLE listens for `CM_SLAC_MATCH.REQ` from PEV-HLE and abandons the session if no indication is received within a reasonable time. If an indication is received then this function compares `RunID` from `CM_SLAC_MATCH.REQ` to the session.RunID to ensure the message is part of the current session. This function compares `APPLICATION_TYPE` and `SECURITY_TYPE` to the session.APPLICATION_TYPE and session.SECURITY_TYPE to ensure that they have not changed. This function copies `PEV_ID` and `PEV_MAC` from `CM_SLAC_MATCH.REQ` to the session variable for later use. This function updates session.NMK and session.NID with random values. This function copies session.EVSE_ID, session.EVSE_MAC, session.NMK and session.NID to `CM_SLAC_MATCH.RSP` and sends it unicast to the selecing PEV-HLE.

## evse_cm_set_key

      				signed evse_cm_mnbc_sound
       				struct session * session
       				struct channel * channel
       				struct message * message

## pev_cm_set_key

      				signed pev_cm_mnbc_sound
       				struct session * session
       				struct channel * channel
       				struct message * message