HARDSTACK APIs PROTOCOL
Hardstack being a cabled logic engine made out of multiple FSMs and mainly coded in VHDL, the communication protocol over the two asynchronous serial ports, both for the Data API and the Configuration API between Hardstack module and a PC Server must be as simple and secure as possible (Side channel safe), so that the implementation of these protocols CODECs stays as simple as possible through FSMs in VHDL, but also in the language of your choice on the secure PC server. Simplicity is key for security, and state-of-the-art secure implementation in general.
GENERAL REMARKS ON THE PROTOCOL
For both API over the two asynchronous serial ports, there is no master of slave notion for the communication protocol. The protocol is fully balanced. Both the PC Server and Hardstack can send a request/command/data to the other side when something is needed, then the other side has to acknowledge it. We don’t any Frame transmission bit errors, but we provide with this a basic error detection and retransmission mechanism in case of transmission errors occurs on the serial lines, in can always happen from time to time as we use high speed clocks. It is recommended to use a short and well shielded cable. Any side who sends a given command cannot send another same command type until the other side acknowledged it first, this means that in each transmission direction, there is a maximum of one pending command/request sent “per command/request type codes and per socket slot”, always. Acknowledgment frames don’t need to be acknowledged themselves.
For this documentation of the protocol format used for the two serial ports used respecively for the Config API and the Data API of Hardstack, each bullet list item describes a given field meaning for a given message frame, its size in bytes (Most of the time a fixed value), and its encoding informations (Sometimes such field has a bitmapped content). All fields on more than one bytes are always Big Endian encoded, because Little Endian suchs for debugging.
Frames incremental counter numbers are local to each side of the serial link. Each starting from zero for each side, and looping to zero when reaching 255 value.
DATA API PROTOCOL
Hardstack -> PC Frames :
Acknowledgement for PC -> Hardstack frames :
These frames are sent immediatly by Hardstack to acknowledge each acknowledgeable frame received from the PC. Through it, Hardstack can request to the PC to resent the last frame sent, if it contains a CRC 32 check error.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “PC Frames Acknowledgment” <0×03> : 1 Byte
- Incremental Hardstack Frame Number Counter : 1 Byte
- Flags (Bitmap : Bit 1 : 0 = Received Frame CRC OK, 1 = Received Frame CRC ERROR Retransmit the Erroneous Frame ) : 1 Byte
- PC Frame Number to Acknowledge : 1 Byte
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
Hardstack Reset or Power-Up :
This frame is sent by Hardstack everytime it performs a Reset or a Power-Up. This frame also means that frames counters on both sides shall be reinitialized to zero after the frame is received. This frame is not acknowledgeable (It has no frame counter field). This frame also informs the PC server of some key parameters necessary to implement the protocol properly, including some necessary informations regarding the Socket Slots configuration for each socket slot.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “Hardstack Reset or Power-Up” <0×07> : 1 Byte
- Protocol Version - Current version is <0×00> : 1 Byte
- Number of Socket Slots (Referred to later on in this document as NSS) installed and operating (8 Sockets Slots available means a value of <0×08>) : 1 Byte
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
Ethernet Link Status :
This frame is sent by Hardstack everytime its internal state of the Ethernet Physical Link changes. After a Reset or a Power-Up, the internal Ethernet Physical Link status is always set to “NO LINK”. Hardstack informs the PC server of its evolution with this frame, as it changes over time.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “Ethernet Link Status” <0×09> : 1 Byte
- Incremental Hardstack Frame Number Counter : 1 Byte
- Link Status, encoded in two bits (Encoding : <0×00> = NO LINK, <0×01> = NLP TX, <0×02> = NLP RX, <0×03> = LINK OK) : 1 Byte
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
TCP Socket Connexion :
This frame is used to signal the PC that a given socket is now connected. From the reception of this frame by the PC, Hardstack will begin transferring data to the PC for this socket. Similarly, the PC can start sending data for this socket to Hardstack after he receives this frame.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “TCP Socket Connexion” <0×01> : 1 Byte
- Incremental Hardstack Frame Number Counter : 1 Byte
- Socket slot number (Valid value range : 0 to NSS-1) : 1 Byte
- Flags (Bitmap : Bit 1 : 0 = Remote Host IP Address Mode, 1 = Remote Host Anonymous ID Mode ) : 1 Byte
- Remote Host IP Address (IP Address or Anonymous ID) : 4 Byte
- Remote Host IP Port (IP Port or Anonymous ID) : 2 Bytes
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
TCP Socket Disconnection :
This frame is used to signal the PC that a given socket is now disconnected. No more socket data will be transmitted to the PC for this socket after this frame is sent to the PC. The PC shall not send more socket data frames to the given socket after this frame is received, they would simply be ignored if he dares to.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “TCP Socket Disconnexion” <0×04> : 1 Byte
- Incremental Hardstack Frame Number Counter : 1 Byte
- Socket slot number (Valid value range : 0 to NSS-1) : 1 Byte
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
TCP Socket Data :
This frame is used by Hardstack to transfer data received from the Ethernet Link on a connected TCP socket. Hardstack will never send such frame if the socket is disconnected. Hardstack will always transfer all its pending received data for a socket to the PC with this frame, before sending a disconnect frame if the sockets gets disconnected. This way, the PC has the garantee to always received all the received data for a given socket, even when the socket gets disconnected.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “TCP Socket Data” <0×05> : 1 Byte
- Incremental Hardstack Frame Number Counter : 1 Byte
- Socket slot number (Valid value range : 0 to NSS-1) : 1 Byte
- Flags (Bitmap : Bit 0 : 0 = No more data to come after these ones, 1 = More data to come) : 1 Byte
- Data size N (Unsigned and coded with 15 bits, the most significant bit must be zero) : 2 Bytes
- Data : N Bytes
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
UDP Socket Data :
This frame is used by Hardstack to transfer data received from the Ethernet Link on a UDP socket slot to the server. As UDP is connexion-less, and as a UDP socket slot can be configured to accept UDP datagrams from only one or from several different remote hosts, each UDP datagram received by Hardstack is always associated to a remote host IP and port. When the anonymous mode is used for a given Socket Slot, the remote host IP and Port are replaced by an anonymous identifier coded on 6 bytes and guaranteed constant over time.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “UDP Socket Data” <0×0A> : 1 Byte
- Incremental Hardstack Frame Number Counter : 1 Byte
- Socket slot number (Valid value range : 0 to NSS-1) : 1 Byte
- Flags (Bitmap : Bit 0 : 0 = No more data to come after these ones, 1 = More data to come -
Bit 1 : 0 = Remote Host IP Address Mode, 1 = Remote Host Anonymous ID Mode ) : 1 Byte
- Remote Host IP Address (IP Address or Anonymous ID) : 4 Byte
- Remote Host IP Port (IP Port or Anonymous ID) : 2 Bytes
- Data size N (Unsigned and coded with 15 bits, the most significant bit must be zero) : 2 Bytes
- Data : N Bytes
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
PC -> Hardstack Frames :
Acknowledgement for Hardstack -> PC frames :
These frames are sent immediately by the PC to acknowledge each acknowledgeable frame received from Hardstack. Through it, the PC can request to Hardstack to resent the last frame sent, if it contains a CRC 32 check error.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “Hardstack Frames Acknowledgment” <0×02> : 1 Byte
- Incremental PC Frame Number Counter : 1 Byte
- Flags (Bitmap : Bit 1 : 0 = Received Frame CRC OK, 1 = Received Frame CRC ERROR Retransmit the Erroneous Frame ) : 1 Byte
- Hardstack Frame Number to Acknowledge : 1 Byte
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
PC Reset or Power-Up :
This frame is sent by the PC server everytime it performs a Reset or a Power-Up of its server application (Meaning when it starts opening and handling the serial port with this protocol. This frame also means that frames counters on both sides shall be reinitialized to zero after the frame is received. This frame is not acknowledgeable (It has no frame counter field).
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “PC Reset or Power-Up” <0×08> : 1 Byte
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
TCP Socket Data :
This frame is used by the PC to transfer data on a given TCP socket, if it is connected. If the socket is not connected, this frame will be ignored by Hardstack. If the amount of data to transfer into the socket is less or equal to the maximum size transferable with such frame, you shall set the “No more data to come after these ones” Bit 0 to zero in the Flags field : This guarantees that these data will be sent immediately by Hardstack into the socket to the remote peer. If amount of data to transfer into the socket is greater than the maximum size transferable with such frame, you shall set the “More data to come” Bit 0 to one in the Flags field. This bit controls the internal mechanism in Hardstack that wait to fill a full datagram MTU before sending it or not.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “TCP Socket Data” <0×06> : 1 Byte
- Incremental PC Frame Number Counter : 1 Byte
- Socket slot number (Valid value range : 0 to NSS-1) : 1 Byte
- Flags (Bitmap : Bit 0 : 0 = No more data to come after these ones, 1 = More data to come) : 1 Byte
- Data size N (Unsigned and coded with 15 bits, the most significant bit must be zero) : 2 Bytes
- Data : N Bytes
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
UDP Socket Data :
This frame is used by the server to transfer data to an UDP socket slot on Hardstack. As UDP is connexion-less, and as a UDP socket slot can be configured to accept UDP datagrams from only one or from several different remote hosts, each UDP data sent to Hardstack is always associated to a remote host IP and port. When the anonymous mode is used for a given Socket Slot, the remote host IP and Port are replaced by an anonymous identifier guaranteed constant over time.
- Start of Frame - STX : <0×02> : 1 Byte
- Frame content size in bytes, excluding SOF and EOF bytes : 2 Bytes
- Frame message type code for “UDP Socket Data” <0×0B> : 1 Byte
- Incremental Hardstack Frame Number Counter : 1 Byte
- Socket slot number (Valid value range : 0 to NSS-1) : 1 Byte
- Flags (Bitmap : Bit 0 : 0 = No more data to come after these ones, 1 = More data to come -
Bit 1 : 0 = Remote Host IP Address Mode, 1 = Remote Host Anonymous ID Mode ) : 1 Byte
- Remote Host IP Address (IP Address or Anonymous ID) : 4 Byte
- Remote Host IP Port (IP Port or Anonymous ID) : 2 Bytes
- Data size N (Unsigned and coded with 15 bits, the most significant bit must be zero) : 2 Bytes
- Data : N Bytes
- CRC 32 of all frame bytes, excluding SOF, CRC 32, and EOF bytes in the frame : 4 Bytes
- End of Frame - ETX : <0×03> : 1 Byte
CONFIG API PROTOCOL
Hardstack -> PC :
PC -> Hardstack :
WORK IN PROGRESS - NOT FINAL RELEASE - THIS POST IS UNDER CONTINUOUS MODIFICATIONS UNTIL DECLARED FINISHED !