void SparkProtocol::notify_update_done(uint8_t* buf) { serial_dump("Sending UpdateDone"); unsigned short message_id = next_message_id(); buf[0] = 0x50; // non-confirmable, no token buf[1] = 0x02; // POST buf[2] = message_id >> 8; buf[3] = message_id & 0xff; buf[4] = 0xb1; // Uri-Path option of length 1 buf[5] = 'u'; memset(buf + 6, 10, 10); // PKCS #7 padding encrypt(buf, 16); }
void SparkProtocol::function_return(unsigned char *buf, unsigned char token, int return_value) { unsigned short message_id = next_message_id(); buf[0] = 0x51; // non-confirmable, one-byte token buf[1] = 0x44; // response code 2.04 CHANGED buf[2] = message_id >> 8; buf[3] = message_id & 0xff; buf[4] = token; buf[5] = 0xff; // payload marker buf[6] = return_value >> 24; buf[7] = return_value >> 16 & 0xff; buf[8] = return_value >> 8 & 0xff; buf[9] = return_value & 0xff; memset(buf + 10, 6, 6); // PKCS #7 padding encrypt(buf, 16); }
void SparkProtocol::hello(unsigned char *buf, bool newly_upgraded) { unsigned short message_id = next_message_id(); buf[0] = 0x50; // non-confirmable, no token buf[1] = 0x02; // POST buf[2] = message_id >> 8; buf[3] = message_id & 0xff; buf[4] = 0xb1; // Uri-Path option of length 1 buf[5] = 'h'; buf[6] = 0xff; // payload marker buf[7] = product_id >> 8; buf[8] = product_id & 0xff; buf[9] = product_firmware_version >> 8; buf[10] = product_firmware_version & 0xff; buf[11] = 0; // reserved flags buf[12] = newly_upgraded ? 1 : 0; buf[13] = PLATFORM_ID >> 8; buf[14] = PLATFORM_ID & 0xFF; memset(buf + 15, 1, 1); // PKCS #7 padding encrypt(buf, 16); }
void add_message(struct message* msg) { char* ptr = small_buf; next_message_id(&ptr); copy_string(context->msg_id, small_buf, CHAR_BUFFER_SIZE); context->msg = msg; }