Updated on 2023-10-18 GMT+08:00

PCP Introduction

The PCP protocol stipulates the communication content and format between the IoT platform and devices.

PCP runs at the application layer for device upgrade.

Communication Method

  1. PCP runs at the application layer. LwM2M, CoAP, MQTT, or others can be used at the underlying layer.
  2. PCP messages are not allocated with independent ports and are independent from protocols at the underlying layer. To differentiate PCP messages from device service messages, 0XFFFE is used as the start bytes of the PCP messages, and the first two bytes of the service messages cannot be 0XFFFE. For details, see PCP Message Identification.
  3. PCP uses a question-and-answer communication mode. All request messages have a response message.

Message Structure

Field

Type

Description

Start ID

WORD

The value is fixed at 0XFFFE.

Version

BYTE

The four most significant bits are reserved. The four least significant bits indicate the protocol version. Currently, the version is 1.

Message code

BYTE

Type of the request exchanged between the platform and device. The message code of a response is the same as that of the request. The following message codes have been defined:

  • 0-18: reserved
  • 19: device version query
  • 20: software package notification
  • 21: software package download
  • 22: download result reporting
  • 23: upgrade execution
  • 24: upgrade result reporting
  • 25-127: reserved

Check code

WORD

CRC16 check value calculated from the start ID to the last byte of the data zone. Before the calculation, this field is set to 0. The result is then written to the field after the CRC16 calculation.

NOTE:

CRC16 algorithm: CRC16/CCITT x16+x12+x5+1

Data zone length

WORD

Length of the data zone.

Data zone

BYTE[n]

Variable length, which is defined by each instruction. For details, see the definitions of the request and response corresponding to each instruction.

Data Type

Data Type

Description

BYTE

Unsigned 1-byte integer

WORD

Unsigned 2-byte integer

DWORD

Unsigned 4-byte integer

BYTE[n]

Hexadecimal number of n bytes

STRING

String

PCP uses the network sequence to transmit WORD and DWORD data.

Device Version Query

Request

Direction: from the platform to a device

Field

Data Type

Description

No data zone

Response

Direction: from a device to the platform

Field

Data Type

Description

Result code

BYTE

The value is 0X00, indicating that the processing was successful.

Current version

BYTE[16]

The version is described using ASCII characters. If there are not enough available digits, 0X00 is appended.

  • The platform determines whether the device needs to be upgraded based on the version. If it does, the platform sends a request to upgrade the device.
  • If the response times out, the platform stops the upgrade task.

Software Package Notification

Request

Direction: from the platform to a device

Field

Data Type

Description

Target version

BYTE[16]

The version is described using ASCII characters. If there are not enough available digits, 0X00 is appended.

Upgrade package segment size

WORD

Size of each segment.

Number of upgrade package segments

WORD

Number of upgrade package segments.

Check code

WORD

The value is fixed at 0000.

Response

Direction: from a device to the platform

Field

Data Type

Description

Result code

BYTE

0X00: The upgrade is allowed.

0X01: The device is in use.

0X02: The signal is weak.

0X03: The latest version is in use.

0X04: The battery power is low.

0X05: The remaining space is insufficient.

0X09: The memory is insufficient.

0X7F: An internal error has occurred.

  • If the upgrade is not allowed by the device, the platform stops the upgrade task.
  • If the response times out, and the request for the upgrade package is not received, the platform stops the upgrade task.

Software Package Requesting

Request

Direction: from a device to the platform

Field

Data Type

Description

Target version

BYTE[16]

The version is described using ASCII characters. If there are not enough available digits, 0X00 is appended.

Segment sequence number

WORD

Sequence number of the requested segment. The value starts from 0. The total number of segments is obtained by rounding up the result of the software package size divided by the segment size. The device can save the received segments and request for the missing segments next time. Resumable download is supported.

Response

Direction: from the platform to a device

Field

Data Type

Description

Result code

BYTE

0X00: The processing was successful.

0X80: The upgrade task does not exist.

0X81: The specified segment does not exist.

Segment sequence number

WORD

Sequence number of a returned segment.

Segment data

BYTE[n]

Content of the segment. n indicates the segment size. If the result code is not 0, this field is not included.

Download Result Reporting

Request

Direction: from a device to the platform

Field

Data Type

Description

Download status

BYTE

0X00: The upgrade package has been downloaded.

0X05: The remaining space is insufficient.

0X06: The download timed out.

0X07: The upgrade package failed to be verified.

0X08: The upgrade package is not supported.

Response

Direction: from the platform to a device

Field

Data Type

Description

Result code

BYTE

0X00: The processing was successful.

0X80: The upgrade task does not exist.

Upgrade Execution

Request

Direction: from the platform to a device

Field

Data Type

Description

No data zone

Response

Direction: from a device to the platform

Field

Data Type

Description

Result code

BYTE

0X00: The processing was successful.

0X01: The device is in use.

0X04: The battery power is low.

0X05: The remaining space is insufficient.

0X09: The memory is insufficient.

Upgrade Result Reporting

Request

Direction: from a device to the platform

Field

Data Type

Description

Result code

BYTE

0X00: The upgrade was successful.

0X01: The device is in use.

0X04: The battery power is low.

0X05: The remaining space is insufficient.

0X09: The memory is insufficient.

0X0A: The upgrade package failed to be installed.

0X7F: An internal error has occurred.

Current version

BYTE[16]

Current version of the device.

Response

Direction: from the platform to a device

Field

Data Type

Description

Result code

BYTE

0X00: The processing was successful.

0X80: The upgrade task does not exist.

PCP Message Identification

PCP messages and device service messages share the same port and URL. When receiving a message from the device, the platform performs the following steps to determine whether the message is a PCP message or a service message:

  1. Checks whether the device supports software upgrades (defined by omCapability.upgradeCapability in the product model). If the device does not support software upgrades, the message is considered to be a service message.
  2. Checks whether the software upgrade protocol is PCP. If the protocol is not PCP, the message is considered to be a service message.
  3. Checks whether the first two bytes of the message are 0XFFFE. If the bytes are not 0XFFFE, the message is considered to be a service message.
  4. Checks whether the version is valid. If the version is invalid, the message is considered as a service message.
  5. Checks whether the message code is valid. If the message code is invalid, the message is considered as a service message.
  6. Checks whether the check code is correct. If the check code is incorrect, the service message is considered to be a service message.
  7. Checks whether the length of the data zone is correct. If the length is incorrect, the message is considered to be a service message.
  8. If all the preceding check items are passed, the message is considered as a PCP message.

The start bytes of a service message cannot be 0XFFFE.