Exemplo n.º 1
0
void client_send_red_brick_enumerate(Client *client, EnumerationType type) {
    EnumerateCallback enumerate_callback;
    uint32_t uid = red_usb_gadget_get_uid(); // always little endian

    memset(&enumerate_callback, 0, sizeof(enumerate_callback));

    enumerate_callback.header.uid = uid;
    enumerate_callback.header.length = sizeof(enumerate_callback);
    enumerate_callback.header.function_id = CALLBACK_ENUMERATE;
    packet_header_set_sequence_number(&enumerate_callback.header, 0);
    packet_header_set_response_expected(&enumerate_callback.header, true);

    base58_encode(enumerate_callback.uid, uint32_from_le(uid));
    enumerate_callback.connected_uid[0] = '0';
    enumerate_callback.position = '0';
    enumerate_callback.hardware_version[0] = 1; // FIXME
    enumerate_callback.hardware_version[1] = 0;
    enumerate_callback.hardware_version[2] = 0;
    enumerate_callback.firmware_version[0] = _redapid_version[0];
    enumerate_callback.firmware_version[1] = _redapid_version[1];
    enumerate_callback.firmware_version[2] = _redapid_version[2];
    enumerate_callback.device_identifier = uint16_to_le(RED_BRICK_DEVICE_IDENTIFIER);
    enumerate_callback.enumeration_type = type;

    client_dispatch_response(client, NULL, (Packet *)&enumerate_callback, true, false);
}
Exemplo n.º 2
0
static void red_stack_spi_insert_position(REDStackSlave *slave) {
	if (_red_stack.packet_from_spi.header.function_id == CALLBACK_ENUMERATE ||
	    _red_stack.packet_from_spi.header.function_id == FUNCTION_GET_IDENTITY) {
		EnumerateCallback *enum_cb = (EnumerateCallback *)&_red_stack.packet_from_spi;

		if (enum_cb->position == '0') {
			enum_cb->position = '0' + slave->stack_address + 1;
			base58_encode(enum_cb->connected_uid, uint32_from_le(red_usb_gadget_get_uid()));
		}
	}
}