コード例 #1
0
// documented in xbee/ota_client.h
int xbee_ota_init( xbee_ota_t *ota, wpan_dev_t *dev, const addr64 *target)
{
	wpan_envelope_t							envelope;
	int											error;

	if (ota == NULL || dev == NULL || target == NULL)
	{
		return -EINVAL;
	}

	ota->dev = dev;
	ota->target = *target;

	xbee_cbuf_init( &ota->rxbuf.cbuf, 255);

	wpan_envelope_create( &envelope, dev, target, WPAN_NET_ADDR_UNDEFINED);
	envelope.profile_id = WPAN_PROFILE_DIGI;
	envelope.source_endpoint = WPAN_ENDPOINT_DIGI_DATA;
	envelope.dest_endpoint = WPAN_ENDPOINT_DIGI_DATA;
	envelope.cluster_id = DIGI_CLUST_PROG_XBEE_OTA_UPD;
	envelope.options = (ota->flags & XBEE_OTA_FLAG_APS_ENCRYPT) ?
		WPAN_CLUST_FLAG_ENCRYPT : WPAN_SEND_FLAG_NONE;

	if (ota->auth_length)
	{
		envelope.length = ota->auth_length;
		envelope.payload = ota->auth_data;
	}
	else
	{
		// payload must be at least one byte (default to '\0')
		envelope.length = 1;
		envelope.payload = "";
	}

	// tell app to start receiving firmware update
	error = wpan_envelope_send( &envelope);
	if (error)
	{
		return error;
	}

	// Tell bootloader to start receiving in case app isn't running.  Better to
	// do this second, in case application on target is using Transparent
	// Serial for something else.
	envelope.payload = "F";
	envelope.length = 1;
	envelope.cluster_id = DIGI_CLUST_SERIAL;
	wpan_envelope_send( &envelope);

	xbee_xmodem_tx_init( &ota->xbxm, XBEE_XMODEM_FLAG_64);

	return xbee_xmodem_set_stream( &ota->xbxm, _xbee_ota_xmodem_read,
													_xbee_ota_xmodem_write, ota);
}
コード例 #2
0
/**
	@brief
	Send response to a Commissioning Server Cluster request.
*/
int zcl_comm_response( const wpan_envelope_t FAR *envelope,
																		uint_fast8_t status)
{
	const zcl_header_nomfg_t FAR *zcl;
	wpan_envelope_t reply_env;
	PACKED_STRUCT {
		zcl_header_nomfg_t		header;
		uint8_t						status;
	} reply;
	int retval;

	// wpan_envelope_reply() will test for envelope == NULL
	retval = wpan_envelope_reply( &reply_env, envelope);
	if (retval != 0)
	{
		return retval;
	}

	zcl = envelope->payload;
	reply.header.frame_control = ZCL_FRAME_SERVER_TO_CLIENT
										| ZCL_FRAME_DISABLE_DEF_RESP
										| ZCL_FRAME_TYPE_CLUSTER;
	reply.header.sequence = zcl->sequence;
	reply.header.command = zcl->command;
	reply.status = (uint8_t) status;

	reply_env.payload = &reply;
	reply_env.length = sizeof reply;

	return wpan_envelope_send( &reply_env);
}
コード例 #3
0
/* START _FUNCTION DESCRIPTION *******************************************
_zcl_comm_command_send                  <zcl_commissioning.c>

SYNTAX:
   int _zcl_comm_command_send( wpan_envelope_t FAR *envelope)

DESCRIPTION:

     Common function used by zcl_comm_restart_device and zcl_comm_reset_parameters

     sends the envelope and then resets the payload and length before returning

**************************************************************************/
int _zcl_comm_command_send( wpan_envelope_t FAR *envelope)
{
	int retval;

	retval = wpan_envelope_send( envelope);

	// reset payload and length of envelope
	envelope->payload = NULL;
	envelope->length = 0;

	return retval;
}
コード例 #4
0
/*** EndHeader */
int xbee_ota_server_cmd( const wpan_envelope_t FAR *envelope,
	void FAR *context)
{
	uint16_t options;
	const char *err = NULL;

	if (envelope == NULL)
	{
		// Stack should not pass NULL envelope; cover this condition for safety
		return -EINVAL;
	}

	// If cluster configuration requires encryption, make sure this
	// frame was received encrypted.

	options = envelope->options &
		(WPAN_ENVELOPE_RX_APS_ENCRYPT | WPAN_CLUST_FLAG_ENCRYPT);
	if (options == WPAN_CLUST_FLAG_ENCRYPT)
	{
		// cluster requires encryption, but frame wasn't encrypted
		// This isn't ZCL, so we can't send a Default Response and we
		// just have to ignore the message.
		err = "encryption required";
	}
	else
	{
		// call function provided by the application for starting the update
		err = xbee_update_firmware_ota( envelope, context);

		// xbee_update_firmware_ota won't return if it's able to install the
		// update and reboot
	}

	if (err)
	{
		wpan_envelope_t reply;

		if (wpan_envelope_reply( &reply, envelope) == 0)
		{
			reply.payload = err;
			reply.length = strlen( err);

			wpan_envelope_send( &reply);
		}
	}

	return 0;
}
コード例 #5
0
/* START FUNCTION DESCRIPTION ********************************************
zcl_comm_response                       <zcl_commissioning.c>

SYNTAX:
   int zcl_comm_response( const wpan_envelope_t FAR *envelope, 
                          uint_fast8_t status)

DESCRIPTION:
     Send response to a Commissioning Server Cluster request.

**************************************************************************/
int zcl_comm_response( const wpan_envelope_t FAR *envelope,
																		uint_fast8_t status)
{
	const zcl_header_nomfg_t FAR *zcl = envelope->payload;
	wpan_envelope_t reply_env;
	struct {
		zcl_header_nomfg_t		header;
		uint8_t						status;
	} reply;

	reply.header.frame_control = ZCL_FRAME_SERVER_TO_CLIENT
										| ZCL_FRAME_DISABLE_DEF_RESP
										| ZCL_FRAME_TYPE_CLUSTER;
	reply.header.sequence = zcl->sequence;
	reply.header.command = zcl->command;
	reply.status = (uint8_t) status;

	wpan_envelope_reply( &reply_env, envelope);
	reply_env.payload = &reply;
	reply_env.length = sizeof reply;

	return wpan_envelope_send( &reply_env);
}