Mistake on this page? Email us

Writing a device application for provisioning using FCU

After Factory Configurator Utility (FCU) bundles the device credentials and data, your factory tool sends the FCU provisioning bundle to the device application.

To provision a device, your device application must call Factory Configurator Client (FCC) APIs to perform a series of operations in sequence:

  1. Initialize FCC.
  2. Receive the FCU bundle.
  3. Process the bundle.
  4. Finalize FCC.

For a reference implementation of the FCC APIs in a device application for provisioning, please see factory-configurator-client-example.

For details about the FCC APIs, please see the FCC API documentation.

Initializing FCC

Call the fcc_init() function to initialize FCC at the beginning of your application code:

#include "factory_configurator_client.h"
#include "fcc_status.h"

int main() {
    ...
    fcc_status_e fcc_status;

    fcc_status = fcc_init();
    if(fcc_status != FCC_STATUS_SUCCESS) {
        return 1;
    }
    ...
}

Receiving the FCU bundle

Your factory tool client receives the FCU bundle and passes it to FCC.

FCU can send several messages per connection session to FCC.

When FCU sends the last message to FCC, the status of the session switches from open to closed.

Call the fcc_is_session_finished() API to detect the status of the connection session and trigger the logic to close the communication layer:

#include "factory_configurator_client.h"
	...
	fcc_status_e fcc_status;

	//After processing the FCU bundle

	if(fcc_is_session_finished()){
		//Last message logic
		...

	} else {
		//Intermediate message logic
		...
	}


	...

Processing the FCU bundle

Call the fcc_bundle_handler() function to:

  1. Receive the bundle.
  2. Parse the bundle.
  3. Save the bundled data to the device's secure storage.
  4. Create a response bundle.

Note: The fcc_bundle_handler() function allocates the response bundle. You need to free the response bundle using the free() function, as shown in the example code.

#include "fcc_bundle_handler.h"

uint8_t fcu_blob[2000] = {...}; // Buffer with FCU blob
uint8_t *response_blob = NULL;
uint32_t response_blob_size;

// Store bootstrap configuration parameter
fcc_status = fcc_bundle_handler(fcu_blob,
                                  sizeof(fcu_blob),
                                  &response_blob,
                                  &response_blob_size);
// Check whether the function succeeded and whether the response blob was allocated
if(fcc_status != FCC_STATUS_SUCCESS || response_blob == NULL || response_blob_size == 0) {
    // Free the response blob before exiting the function, if allocation succeeds
    free(response_blob)
    return 1;
}

Finalizing FCC

Use the fcc_finalize() function to finalize FCC, release resources, and conclude the workflow:

    fcc_status = fcc_finalize();
    if(fcc_status != FCC_STATUS_SUCCESS) {
        return 1;
    }
    ...
}

Removing FCC code from the production image

FCC APIs allow overwriting or manipulating provisioning information stored on the device.

FCC code is not operational in production devices.

To remove the FCC code from the device at the end of provisioning process:

  1. Remove FCC source files and headers from the build configuration of the image.

    mbed-cloud-client/factory-configurator-client contains FCC code.

    These folders contain factory tool client demo code:

    • ftcd-comm-base.
    • ftcd-comm-serial.
    • ftcd-comm-socket.
  2. Compile and flash the image without the FCC code.

Note: To enhance security in the production environment, avoid remote access to the FCC APIs.