示例#1
0
文件: pbap.c 项目: Sork007/obexd
static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
					DBusMessage *message, const char *name,
					guint8 order, char *searchval, guint8 attrib,
					guint16 count, guint16 offset)
{
	guint8 *p, *apparam = NULL;
	gint apparam_size;
	int err;

	if (pbap->msg)
		return g_dbus_create_error(message,
				"org.openobex.Error.InProgress",
				"Transfer in progress");

	/* trunc the searchval string if it's length exceed the max value of guint8 */
	if (strlen(searchval) > 254)
		searchval[255] = '\0';

	apparam_size = APPARAM_HDR_SIZE + ORDER_LEN +
			(APPARAM_HDR_SIZE + strlen(searchval) + 1) +
			(APPARAM_HDR_SIZE + SEARCHATTRIB_LEN) +
			(APPARAM_HDR_SIZE + MAXLISTCOUNT_LEN) +
			(APPARAM_HDR_SIZE + LISTSTARTOFFSET_LEN);
	apparam = g_try_malloc0(apparam_size);
	if (!apparam)
		return g_dbus_create_error(message,
				ERROR_INF ".Failed", "No Memory");

	p = apparam;

	p = fill_apparam(p, &order, ORDER_TAG, ORDER_LEN);
	p = fill_apparam(p, searchval, SEARCHVALUE_TAG, strlen(searchval) + 1);
	p = fill_apparam(p, &attrib, SEARCHATTRIB_TAG, SEARCHATTRIB_LEN);

	count = GUINT16_TO_BE(count);
	p = fill_apparam(p, &count, MAXLISTCOUNT_TAG, MAXLISTCOUNT_LEN);

	offset = GUINT16_TO_BE(offset);
	p = fill_apparam(p, &offset, LISTSTARTOFFSET_TAG, LISTSTARTOFFSET_LEN);

	err = obc_session_get(pbap->session, "x-bt/vcard-listing", name, NULL,
				apparam, apparam_size,
				pull_vcard_listing_callback, pbap);
	g_free(apparam);
	if (err < 0)
		return g_dbus_create_error(message,
				"org.openobex.Error.Failed",
				"Failed");

	pbap->msg = dbus_message_ref(message);

	return NULL;
}
示例#2
0
文件: pbap.c 项目: Sork007/obexd
static DBusMessage *pull_phonebook(struct pbap_data *pbap,
					DBusMessage *message, guint8 type,
					const char *name, uint64_t filter,
					guint8 format, guint16 maxlistcount,
					guint16 liststartoffset)
{
	struct pullphonebook_apparam apparam;
	session_callback_t func;

	if (pbap->msg)
		return g_dbus_create_error(message,
				"org.openobex.Error.InProgress",
				"Transfer in progress");

	apparam.filter_tag = FILTER_TAG;
	apparam.filter_len = FILTER_LEN;
	apparam.filter = GUINT64_TO_BE(filter);
	apparam.format_tag = FORMAT_TAG;
	apparam.format_len = FORMAT_LEN;
	apparam.format = format;
	apparam.maxlistcount_tag = MAXLISTCOUNT_TAG;
	apparam.maxlistcount_len = MAXLISTCOUNT_LEN;
	apparam.maxlistcount = GUINT16_TO_BE(maxlistcount);
	apparam.liststartoffset_tag = LISTSTARTOFFSET_TAG;
	apparam.liststartoffset_len = LISTSTARTOFFSET_LEN;
	apparam.liststartoffset = GUINT16_TO_BE(liststartoffset);

	switch (type) {
	case PULLPHONEBOOK:
		func = pull_phonebook_callback;
		break;
	case GETPHONEBOOKSIZE:
		func = phonebook_size_callback;
		break;
	default:
		error("Unexpected type : 0x%2x", type);
		return NULL;
	}

	if (obc_session_get(pbap->session, "x-bt/phonebook", name, NULL,
				(guint8 *) &apparam, sizeof(apparam),
				func, pbap) < 0)
		return g_dbus_create_error(message,
				"org.openobex.Error.Failed",
				"Failed");

	pbap->msg = dbus_message_ref(message);

	return NULL;
}
示例#3
0
wtap_open_return_val stanag4607_open(wtap *wth, int *err, gchar **err_info)
{
  guint16 version_id;
  stanag4607_t *stanag4607;

  if (!wtap_read_bytes(wth->fh, &version_id, sizeof version_id, err, err_info))
    return (*err != WTAP_ERR_SHORT_READ) ? WTAP_OPEN_ERROR : WTAP_OPEN_NOT_MINE;

  if (!is_valid_id(GUINT16_TO_BE(version_id)))
     /* Not a stanag4607 file */
     return WTAP_OPEN_NOT_MINE;

  /* seek back to the start of the file  */
  if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
    return WTAP_OPEN_ERROR;

  wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_STANAG_4607;
  wth->file_encap = WTAP_ENCAP_STANAG_4607;
  wth->snapshot_length = 0; /* not known */

  stanag4607 = (stanag4607_t *)g_malloc(sizeof(stanag4607_t));
  wth->priv = (void *)stanag4607;
  stanag4607->base_secs = 0; /* unknown as of yet */

  wth->subtype_read = stanag4607_read;
  wth->subtype_seek_read = stanag4607_seek_read;
  wth->file_tsprec = WTAP_TSPREC_MSEC;

  return WTAP_OPEN_MINE;
}
示例#4
0
guint64
prop_copy_uint16 (guint16 prop, guint8 ** buffer, guint64 * size,
    guint64 * offset)
{
  prop = GUINT16_TO_BE (prop);
  return copy_func (&prop, sizeof (guint16), buffer, size, offset);
}
示例#5
0
文件: directconn.c 项目: VoxOx/VoxOx
void
msn_directconn_parse_nonce(MsnDirectConn *directconn, const char *nonce)
{
	guint32 t1;
	guint16 t2;
	guint16 t3;
	guint16 t4;
	guint64 t5;

	g_return_if_fail(directconn != NULL);
	g_return_if_fail(nonce      != NULL);

	sscanf (nonce, "%08X-%04hX-%04hX-%04hX-%012llX", &t1, &t2, &t3, &t4, &t5);

	t1 = GUINT32_TO_LE(t1);
	t2 = GUINT16_TO_LE(t2);
	t3 = GUINT16_TO_LE(t3);
	t4 = GUINT16_TO_BE(t4);
	t5 = GUINT64_TO_BE(t5);

	directconn->slpheader = g_new0(MsnSlpHeader, 1);

	directconn->slpheader->ack_id     = t1;
	directconn->slpheader->ack_sub_id = t2 | (t3 << 16);
	directconn->slpheader->ack_size   = t4 | t5;
}
示例#6
0
static void
print_address6 (gboolean success,
                const char *tag,
                GArray *array,
                guint32 prefix,
                GError *error)
{
    struct in6_addr a;
    char buf[INET6_ADDRSTRLEN + 1];
    guint32 i;

    if (success) {
        g_assert (array);
        g_assert (array->len == 8);

        memset (buf, 0, sizeof (buf));
        for (i = 0; i < array->len; i++)
            a.s6_addr16[i] = GUINT16_TO_BE (g_array_index (array, guint16, i));

        if (inet_ntop (AF_INET6, &a, buf, sizeof (buf) - 1))
            mm_dbg ("    %s: %s/%d", tag, buf, prefix);
        else
            mm_dbg ("    %s: failed (address conversion error)", tag);

        g_array_free (array, TRUE);
        return;
    }

    mm_dbg ("    %s: failed (%s)", tag, error ? error->message : "unknown");
}
示例#7
0
int stanag4607_open(wtap *wth, int *err, gchar **err_info)
{
    int bytes_read;
    guint16 version_id;
    stanag4607_t *stanag4607;

    bytes_read = file_read(&version_id, sizeof version_id, wth->fh);
    if (bytes_read != sizeof version_id) {
        *err = file_error(wth->fh, err_info);
        return (*err != 0) ? -1 : 0;
    }

    if (!is_valid_id(GUINT16_TO_BE(version_id)))
        /* Not a stanag4607 file */
        return 0;

    /* seek back to the start of the file  */
    if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
        return -1;

    wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_STANAG_4607;
    wth->file_encap = WTAP_ENCAP_STANAG_4607;
    wth->snapshot_length = 0; /* not known */

    stanag4607 = (stanag4607_t *)g_malloc(sizeof(stanag4607_t));
    wth->priv = (void *)stanag4607;
    stanag4607->base_secs = 0; /* unknown as of yet */

    wth->subtype_read = stanag4607_read;
    wth->subtype_seek_read = stanag4607_seek_read;
    wth->tsprecision = WTAP_FILE_TSPREC_MSEC;

    return 1;
}
示例#8
0
文件: object.c 项目: nshi/falcon
void falcon_object_save(trie_node_t *node, void *userdata)
{
	const falcon_object_t *object = (const falcon_object_t *)trie_data(node);
	int fd = GPOINTER_TO_INT(userdata);
	guint16 len = strlen(object->name);
	guint16 len_be = GUINT16_TO_BE(len);
	guint64 size = GUINT64_TO_BE(object->size);
	guint64 time = GUINT64_TO_BE(object->time);
	guint32 mode = GUINT32_TO_BE(object->mode);

	if (write(fd, &len_be, 2) == -1 || write(fd, object->name, len) == -1
	    || write(fd, &size, 8) == -1 || write(fd, &time, 8) == -1
	    || write(fd, &mode, 4) == -1 || write(fd, &(object->watch), 1) == -1)
		g_critical(_("Failed to save object \"%s\": %s"), object->name,
		           g_strerror(errno));
}
示例#9
0
文件: xconvert.c 项目: sedwards/xmms3
static int convert_stereo_to_mono_u16be(struct xmms_convert_buffers* buf, void **data, int length)
{
	guint16 *output = *data, *input = *data;
	int i;
	for (i = 0; i < length / 4; i++)
	{
		guint32 tmp;
		guint16 stmp;
		tmp = GUINT16_FROM_BE(*input);
		input++;
		tmp += GUINT16_FROM_BE(*input);
		input++;
		stmp = tmp / 2;
		*output++ = GUINT16_TO_BE(stmp);
	}
	return length / 2;
}
示例#10
0
文件: directconn.c 项目: VoxOx/VoxOx
void
msn_directconn_send_handshake(MsnDirectConn *directconn)
{
	MsnSlpLink *slplink;
	MsnSlpMessage *slpmsg;

	g_return_if_fail(directconn != NULL);

	slplink = directconn->slplink;

	slpmsg = msn_slpmsg_new(slplink);
	slpmsg->flags = 0x100;

	if (directconn->nonce != NULL)
	{
		guint32 t1;
		guint16 t2;
		guint16 t3;
		guint16 t4;
		guint64 t5;

		sscanf (directconn->nonce, "%08X-%04hX-%04hX-%04hX-%012" G_GINT64_MODIFIER "X", &t1, &t2, &t3, &t4, &t5);

		t1 = GUINT32_TO_LE(t1);
		t2 = GUINT16_TO_LE(t2);
		t3 = GUINT16_TO_LE(t3);
		t4 = GUINT16_TO_BE(t4);
		t5 = GUINT64_TO_BE(t5);

		slpmsg->ack_id     = t1;
		slpmsg->ack_sub_id = t2 | (t3 << 16);
		slpmsg->ack_size   = t4 | t5;
	}

	g_free(directconn->nonce);

	msn_slplink_send_slpmsg(slplink, slpmsg);

	directconn->acked =TRUE;
}
示例#11
0
文件: qmi-utils.c 项目: ebichu/dd-wrt
/**
 * qmi_utils_write_guint16_to_buffer:
 * @buffer: a buffer.
 * @buffer_size: size of @buffer.
 * @endian: endianness of firmware value; swapped from host byte order if necessary
 * @in: location of the variable to be written.
 *
 * Writes an unsigned 16-bit integer into the buffer. The number to be written
 * is expected to be given in host endianness, and this method takes care of
 * converting the value written to the byte order specified by @endian.
 *
 * The user needs to make sure that the buffer is at least 2 bytes long.
 *
 * Also note that both @buffer and @buffer_size get updated after the 2 bytes
 * write.
 */
void
qmi_utils_write_guint16_to_buffer (guint8  **buffer,
                                   guint16  *buffer_size,
                                   QmiEndian endian,
                                   guint16  *in)
{
    guint16 tmp;

    g_assert (in != NULL);
    g_assert (buffer != NULL);
    g_assert (buffer_size != NULL);
    g_assert (*buffer_size >= 2);

    if (endian == QMI_ENDIAN_BIG)
        tmp = GUINT16_TO_BE (*in);
    else
        tmp = GUINT16_TO_LE (*in);
    memcpy (&(*buffer)[0], &tmp, sizeof (tmp));

    *buffer = &((*buffer)[2]);
    *buffer_size = (*buffer_size) - 2;
}
示例#12
0
static gboolean
send_request_sync (GOutputStream     *output,
                   DsiCommand        command,
                   guint16           request_id,
                   guint32           writeOffset,
                   gsize             len,
                   const char        *data,
                   GCancellable      *cancellable,
                   GError            **error)
{
  DSIHeader dsi_header;
  gboolean res;
  gsize write_count, bytes_written;

  dsi_header.flags = 0x00;
  dsi_header.command = command;
  dsi_header.requestID = GUINT16_TO_BE (request_id);
  dsi_header.writeOffset = GUINT32_TO_BE (writeOffset);
  dsi_header.totalDataLength = GUINT32_TO_BE (len); 
  dsi_header.reserved = 0;

  write_count = sizeof (DSIHeader);
  res = g_output_stream_write_all (output, &dsi_header, write_count,
                                   &bytes_written, cancellable, error);
  if (!res)
    return FALSE;

  if (data == NULL)
    return TRUE;

  write_count = len;
  res = g_output_stream_write_all (output, data, write_count, &bytes_written,
                                   cancellable, error);
  if (!res)
    return FALSE;

  return TRUE;
}
示例#13
0
/* XXX toshok - this needs to be done using a signal as in the
 * e_cert_db_login_to_slot stuff, instead of a direct gui dep here..
 * for now, though, it stays. */
static gboolean
prompt_for_password (gchar *title,
                     gchar *prompt,
                     SECItem *pwd)
{
	gchar *passwd;

	passwd = e_passwords_ask_password (
		title, "", prompt,
		E_PASSWORDS_REMEMBER_NEVER | E_PASSWORDS_SECRET,
		NULL, NULL);

	if (passwd) {
		gsize len = strlen (passwd);
		const gchar *inptr = passwd;
		guchar *outptr;
		gunichar2 c;

		SECITEM_AllocItem (NULL, pwd, sizeof (gunichar2) * (len + 1));

		outptr = pwd->data;
		while (inptr && (c = (gunichar2) (g_utf8_get_char (inptr) & 0xffff))) {
			inptr = g_utf8_next_char (inptr);
			c = GUINT16_TO_BE (c);
			*outptr++ = ((gchar *) &c)[0];
			*outptr++ = ((gchar *) &c)[1];
		}

		outptr[0] = 0;
		outptr[1] = 0;

		memset (passwd, 0, strlen (passwd));
		g_free (passwd);
	}

	return TRUE;
}
示例#14
0
void
msn_write16be(char *buf, guint16 data)
{
    data = GUINT16_TO_BE(data);
    memcpy(buf, &data, sizeof(data));
}
示例#15
0
文件: timem.c 项目: debrouxl/tiemu
void wr_word(uint8_t *p, uint16_t d)
{
	uint16_t *p16 = (uint16_t *)p;
	*p16 = GUINT16_TO_BE(d);
}
示例#16
0
文件: convert.c 项目: sedwards/xmms3
static int convert_stereo_to_mono(void **data, int length, int fmt)
{
	int i;

	switch (fmt)
	{
		case AFMT_U8:
		{
			guint8 *output = *data, *input = *data;
			for (i = 0; i < length / 2; i++)
			{
				guint16 tmp;
				tmp = *input++;
				tmp += *input++;
				*output++ = tmp / 2;
			}
		}
		break;
		case AFMT_S8:
		{
			gint8 *output = *data, *input = *data;
			for (i = 0; i < length / 2; i++)
			{
				gint16 tmp;
				tmp = *input++;
				tmp += *input++;
				*output++ = tmp / 2;
			}
		}
		break;
		case AFMT_U16_LE:
		{
			guint16 *output = *data, *input = *data;
			for (i = 0; i < length / 4; i++)
			{
				guint32 tmp;
				guint16 stmp;
				tmp = GUINT16_FROM_LE(*input);
				input++;
				tmp += GUINT16_FROM_LE(*input);
				input++;
				stmp = tmp / 2;
				*output++ = GUINT16_TO_LE(stmp);
			}
		}
		break;
		case AFMT_U16_BE:
		{
			guint16 *output = *data, *input = *data;
			for (i = 0; i < length / 4; i++)
			{
				guint32 tmp;
				guint16 stmp;
				tmp = GUINT16_FROM_BE(*input);
				input++;
				tmp += GUINT16_FROM_BE(*input);
				input++;
				stmp = tmp / 2;
				*output++ = GUINT16_TO_BE(stmp);
			}
		}
		break;
		case AFMT_S16_LE:
		{
			gint16 *output = *data, *input = *data;
			for (i = 0; i < length / 4; i++)
			{
				gint32 tmp;
				gint16 stmp;
				tmp = GINT16_FROM_LE(*input);
				input++;
				tmp += GINT16_FROM_LE(*input);
				input++;
				stmp = tmp / 2;
				*output++ = GINT16_TO_LE(stmp);
			}
		}
		break;
		case AFMT_S16_BE:
		{
			gint16 *output = *data, *input = *data;
			for (i = 0; i < length / 4; i++)
			{
				gint32 tmp;
				gint16 stmp;
				tmp = GINT16_FROM_BE(*input);
				input++;
				tmp += GINT16_FROM_BE(*input);
				input++;
				stmp = tmp / 2;
				*output++ = GINT16_TO_BE(stmp);
			}
		}
		break;
		default:
			g_error("unknown format");
	}

	return length / 2;
}
示例#17
0
/**
 * Writes an unsigned 16-bit native endian value into the stream as a
 * Big Endian value.
 *
 * @param value Value to write into the stream.
 * @param stream A #VFSFile object representing the stream.
 * @return TRUE if read was succesful, FALSE if there was an error.
 */
EXPORT bool_t vfs_fput_be16(uint16_t value, VFSFile *stream)
{
    uint16_t tmp = GUINT16_TO_BE(value);
    return vfs_fwrite(&tmp, sizeof(tmp), 1, stream) == 1;
}
示例#18
0
EXPORT void simple_read_pf(void * data, XmlCmdType type)
{
	Io_Message *message  = NULL;
	OutputData *output  = NULL;
	gint count = 0;
	gchar *tmpbuf = NULL;
	gint page = -1;
	gint canID = -1;
	guint16 curcount = 0;
	static guint16 lastcount = 0;
	extern Firmware_Details *firmware;
	extern gint ms_ve_goodread_count;
	extern gint ms_reset_count;
	extern gint ms_goodread_count;
	guint8 *ptr8 = NULL;
	guint16 *ptr16 = NULL;
	static gboolean just_starting = TRUE;
	extern gboolean forced_update;
	extern gboolean force_page_change;
	extern volatile gboolean offline;


	message = (Io_Message *)data;
	output = (OutputData *)message->payload;

	switch (type)
	{
		case WRITE_VERIFY:
			printf(_("MS2_WRITE_VERIFY not written yet\n"));
			break;
		case MISMATCH_COUNT:
			printf(_("MS2_MISMATCH_COUNT not written yet\n"));
			break;
		case MS1_CLOCK:
			printf(_("MS1_CLOCK not written yet\n"));
			break;
		case MS2_CLOCK:
			printf(_("MS2_CLOCK not written yet\n"));
			break;
		case NUM_REV:
			if (offline)
				break;
			count = read_data(-1,&message->recv_buf,FALSE);
			ptr8 = (guchar *)message->recv_buf;
			firmware->ecu_revision=(gint)ptr8[0];
			if (count > 0)
				thread_update_widget("ecu_revision_entry",MTX_ENTRY,g_strdup_printf("%.1f",((gint)ptr8[0]/10.0)));
			else
				thread_update_widget("ecu_revision_entry",MTX_ENTRY,g_strdup(""));
			break;
		case TEXT_REV:
			if (offline)
				break;
			count = read_data(-1,&message->recv_buf,FALSE);
			if (count > 0)
			{
				thread_update_widget("text_version_entry",MTX_ENTRY,g_strndup(message->recv_buf,count));
				 firmware->txt_rev_len = count;
				firmware->text_revision = g_strndup(message->recv_buf,count);
			}
			break;
		case SIGNATURE:
			if (offline)
				break;
			 count = read_data(-1,&message->recv_buf,FALSE);
                         if (count > 0)
			 {
				 thread_update_widget("ecu_signature_entry",MTX_ENTRY,g_strndup(message->recv_buf,count));
				 firmware->signature_len = count;
				 firmware->actual_signature = g_strndup(message->recv_buf,count);
			 }
			break;
		case MS1_VECONST:
		case MS2_VECONST:
			page = (GINT)OBJ_GET(output->object,"page");
			canID = (GINT)OBJ_GET(output->object,"canID");
			count = read_data(firmware->page_params[page]->length,&message->recv_buf,TRUE);
			if (count != firmware->page_params[page]->length)
				break;
			store_new_block(canID,page,0,
					message->recv_buf,
					firmware->page_params[page]->length);
			backup_current_data(canID,page);
			ms_ve_goodread_count++;
			break;
		case MS1_RT_VARS:
			count = read_data(firmware->rtvars_size,&message->recv_buf,TRUE);
			if (count != firmware->rtvars_size)
				break;
			ptr8 = (guchar *)message->recv_buf;
			/* Test for MS reset */
			if (just_starting)
			{
				lastcount = ptr8[0];
				just_starting = FALSE;
			}
			/* Check for clock jump from the MS, a 
			 * jump in time from the MS clock indicates 
			 * a reset due to power and/or noise.
			 */
			if ((lastcount - ptr8[0] > 1) && \
					(lastcount - ptr8[0] != 255))
			{
				ms_reset_count++;
				printf(_("MS1 Reset detected!, lastcount %i, current %i\n"),lastcount,ptr8[0]);
				gdk_threads_enter();
				gdk_beep();
				gdk_threads_leave();
			}
			else
				ms_goodread_count++;
			lastcount = ptr8[0];
			/* Feed raw buffer over to post_process()
			 * as a void * and pass it a pointer to the new
			 * area for the parsed data...
			 */
			process_rt_vars((void *)message->recv_buf);
			break;
		case MS2_RT_VARS:
			page = (GINT)OBJ_GET(output->object,"page");
			canID = (GINT)OBJ_GET(output->object,"canID");
			count = read_data(firmware->rtvars_size,&message->recv_buf,TRUE);
			if (count != firmware->rtvars_size)
				break;
			store_new_block(canID,page,0,
					message->recv_buf,
					firmware->page_params[page]->length);
			backup_current_data(canID,page);
			ptr16 = (guint16 *)message->recv_buf;
			/* Test for MS reset */
			if (just_starting)
			{
				lastcount = GUINT16_TO_BE(ptr16[0]);
				curcount = GUINT16_TO_BE(ptr16[0]);
				just_starting = FALSE;
			}
			else
				curcount = GUINT16_TO_BE(ptr16[0]);
			/* Check for clock jump from the MS, a 
			 * jump in time from the MS clock indicates 
			 * a reset due to power and/or noise.
			 */
			if ((lastcount - curcount > 1) && \
					(lastcount - curcount != 65535))
			{
				ms_reset_count++;
				printf(_("MS2 rtvars reset detected, lastcount is %i, current %i"),lastcount,curcount);
				gdk_threads_enter();
				gdk_beep();
				gdk_threads_leave();
			}
			else
				ms_goodread_count++;
			lastcount = curcount;
			/* Feed raw buffer over to post_process()
			 * as a void * and pass it a pointer to the new
			 * area for the parsed data...
			 */
			process_rt_vars((void *)message->recv_buf);
			break;
		case MS2_BOOTLOADER:
			printf(_("MS2_BOOTLOADER not written yet\n"));
			break;
		case MS1_GETERROR:
			forced_update = TRUE;
			force_page_change = TRUE;
			count = read_data(-1,&message->recv_buf,FALSE);
			if (count <= 10)
			{
				thread_update_logbar("error_status_view",NULL,g_strdup(_("No ECU Errors were reported....\n")),FALSE,FALSE);
				break;
			}
			if (g_utf8_validate(((gchar *)message->recv_buf)+1,count-1,NULL))
			{
				thread_update_logbar("error_status_view",NULL,g_strndup(((gchar *)message->recv_buf+7)+1,count-8),FALSE,FALSE);
				if (dbg_lvl & (IO_PROCESS|SERIAL_RD))
				{
					tmpbuf = g_strndup(((gchar *)message->recv_buf)+1,count-1);
					dbg_func(IO_PROCESS|SERIAL_RD,g_strdup_printf(__FILE__"\tECU  ERROR string: \"%s\"\n",tmpbuf));
					g_free(tmpbuf);
				}

			}
			else
				thread_update_logbar("error_status_view",NULL,g_strdup("The data came back as gibberish, please try again...\n"),FALSE,FALSE);
			break;
		default:
			break;
	}
}
示例#19
0
/**
 * fwupd_guid_from_string:
 * @guidstr: (nullable): a GUID, e.g. `00112233-4455-6677-8899-aabbccddeeff`
 * @guid: a #fwupd_guid_t, or NULL to just check the GUID
 * @flags: some %FwupdGuidFlags, e.g. %FWUPD_GUID_FLAG_MIXED_ENDIAN
 * @error: A #GError or %NULL
 *
 * Converts a string GUID into its binary encoding. All string GUIDs are
 * formatted as big endian but on-disk can be encoded in different ways.
 *
 * Returns: %TRUE for success
 *
 * Since: 1.2.5
 **/
gboolean
fwupd_guid_from_string (const gchar *guidstr,
			fwupd_guid_t *guid,
			FwupdGuidFlags flags,
			GError **error)
{
	fwupd_guid_native_t gu = { 0x0 };
	gboolean mixed_endian = flags & FWUPD_GUID_FLAG_MIXED_ENDIAN;
	guint64 tmp;
	g_auto(GStrv) split = NULL;

	g_return_val_if_fail (guidstr != NULL, FALSE);

	/* split into sections */
	if (strlen (guidstr) != 36) {
		g_set_error_literal (error,
				     G_IO_ERROR,
				     G_IO_ERROR_INVALID_DATA,
				     "is not valid format");
		return FALSE;
	}
	split = g_strsplit (guidstr, "-", 5);
	if (g_strv_length (split) != 5) {
		g_set_error_literal (error,
				     G_IO_ERROR,
				     G_IO_ERROR_INVALID_DATA,
				     "is not valid format, no dashes");
		return FALSE;
	}
	if (strlen (split[0]) != 8 && strlen (split[1]) != 4 &&
	    strlen (split[2]) != 4 && strlen (split[3]) != 4 &&
	    strlen (split[4]) != 12) {
		g_set_error_literal (error,
				     G_IO_ERROR,
				     G_IO_ERROR_INVALID_DATA,
				     "is not valid format, not GUID");
		return FALSE;
	}

	/* parse */
	if (!g_ascii_string_to_unsigned (split[0], 16, 0, 0xffffffff, &tmp, error))
		return FALSE;
	gu.a = mixed_endian ? GUINT32_TO_LE(tmp) : GUINT32_TO_BE(tmp);
	if (!g_ascii_string_to_unsigned (split[1], 16, 0, 0xffff, &tmp, error))
		return FALSE;
	gu.b = mixed_endian ? GUINT16_TO_LE(tmp) : GUINT16_TO_BE(tmp);
	if (!g_ascii_string_to_unsigned (split[2], 16, 0, 0xffff, &tmp, error))
		return FALSE;
	gu.c = mixed_endian ? GUINT16_TO_LE(tmp) : GUINT16_TO_BE(tmp);
	if (!g_ascii_string_to_unsigned (split[3], 16, 0, 0xffff, &tmp, error))
		return FALSE;
	gu.d = GUINT16_TO_BE(tmp);
	for (guint i = 0; i < 6; i++) {
		gchar buffer[3] = { 0x0 };
		memcpy (buffer, split[4] + (i * 2), 2);
		if (!g_ascii_string_to_unsigned (buffer, 16, 0, 0xff, &tmp, error))
			return FALSE;
		gu.e[i] = tmp;
	}
	if (guid != NULL)
		memcpy (guid, &gu, sizeof(gu));

	/* success */
	return TRUE;
}
示例#20
0
/**
 * osp_device_query:
 *
 * Since: 1.2.11
 **/
static gboolean
osp_device_query (GUsbDevice *device, OspCmd cmd,
		  const guint8 *data_in, gsize data_in_length,
		  guint8 **data_out, gsize *data_out_length,
		  GError **error)
{
	OspProtocolFooter *ftr;
	OspProtocolHeader *hdr;
	gsize actual_length;
	gsize checksum_length = 16; /* always for MD5 */
	gsize payload_length = 0;
	gsize offset_rd = 0;
	gsize offset_wr = 0;
	guint i;
	g_autoptr(GChecksum) csum = NULL;
	g_autofree guint8 *buffer_in = NULL;
	g_autofree guint8 *buffer_out = NULL;

	g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
	g_return_val_if_fail (data_in_length <= 16, FALSE); //FIXME
	g_assert (sizeof(OspProtocolHeader) + sizeof(OspProtocolFooter) == 64);

	/* write header to buffer */
	buffer_in = g_new0 (guint8, OSP_DEVICE_MAX_MSG_LENGTH);
	hdr = (OspProtocolHeader *) buffer_in;
	hdr->start_bytes = GUINT16_TO_BE (0xc1c0);
	hdr->protocol_version = 0x1000;
	hdr->checksum_type = OSP_HEADER_CHECKSUM_KIND_MD5;
	hdr->message_type = cmd;
	hdr->bytes_remaining = sizeof(OspProtocolFooter);
	if (data_out == NULL)
		hdr->flags = OSP_HEADER_FLAG_ACK_REQUIRED;
	if (data_in_length > 0) {
		if (data_in_length <= 16) {
			/* avoid another USB packet if we can */
			hdr->immediate_data_length = data_in_length;
			memcpy (hdr->immediate_data, data_in, data_in_length);
		} else {
			payload_length = data_in_length;
		}
	}
	offset_wr += sizeof(OspProtocolHeader);
	hdr->bytes_remaining = sizeof(OspProtocolFooter) + payload_length;

	/* write payload to buffer, if any */
	if (payload_length > 0) {
		memcpy (buffer_in + offset_wr, data_in, data_in_length);
		offset_wr += payload_length;
	}

	/* write footer to buffer */
	ftr = (OspProtocolFooter *) (buffer_in + offset_wr);
	ftr->end_bytes = GUINT32_TO_BE (0xc5c4c3c2);
	csum = g_checksum_new (G_CHECKSUM_MD5);
	g_checksum_update (csum, (const guchar *) buffer_in, offset_wr);
	g_checksum_get_digest (csum, ftr->checksum, &checksum_length);
	offset_wr += sizeof(OspProtocolFooter);

	/* send data */
	if (g_getenv ("SPARK_PROTOCOL_DEBUG") != NULL)
		cd_buffer_debug (CD_BUFFER_KIND_REQUEST, buffer_in, offset_wr);
	if (!g_usb_device_bulk_transfer (device, 0x01,
					 buffer_in, offset_wr,
					 &actual_length,
					 OSP_USB_TIMEOUT_MS, NULL, error))
		return FALSE;

	/* get reply */
	buffer_out = g_new0 (guint8, 64);
	if (!g_usb_device_bulk_transfer (device, 0x81,
					 buffer_out, OSP_DEVICE_EP_SIZE,
					 &actual_length,
					 OSP_USB_TIMEOUT_MS, NULL, error))
		return FALSE;
	if (g_getenv ("SPARK_PROTOCOL_DEBUG") != NULL)
		cd_buffer_debug (CD_BUFFER_KIND_RESPONSE, buffer_out, actual_length);

	/* check the error code */
	hdr = (OspProtocolHeader *) buffer_out;
	switch (hdr->error_code) {
	case OSP_ERROR_CODE_SUCCESS:
		break;
	case OSP_ERROR_CODE_MESSAGE_TOO_LARGE:
	case OSP_ERROR_CODE_UNKNOWN_CHECKSUM_TYPE:
	case OSP_ERROR_CODE_UNSUPPORTED_PROTOCOL:
		g_set_error (error,
			     OSP_DEVICE_ERROR,
			     OSP_DEVICE_ERROR_NO_SUPPORT,
			     "Failed to %s",
			     osp_cmd_to_string (cmd));
		return FALSE;
		break;
	case OSP_ERROR_CODE_COMMAND_DATA_MISSING:
		g_set_error (error,
			     OSP_DEVICE_ERROR,
			     OSP_DEVICE_ERROR_NO_DATA,
			     "Failed to %s",
			     osp_cmd_to_string (cmd));
		return FALSE;
		break;
	default:
		g_set_error (error,
			     OSP_DEVICE_ERROR,
			     OSP_DEVICE_ERROR_INTERNAL,
			     "Failed to %s: %s",
			     osp_cmd_to_string (cmd),
			     osp_error_code_to_string (hdr->error_code));
		return FALSE;
		break;
	}

	/* copy out the data */
	offset_rd = sizeof(OspProtocolHeader);
	if (data_out != NULL && data_out_length != NULL) {
		if (hdr->immediate_data_length > 0) {
			*data_out_length = hdr->immediate_data_length;
			*data_out = g_memdup (hdr->immediate_data,
					      hdr->immediate_data_length);
		} else if (hdr->bytes_remaining >= sizeof(OspProtocolFooter)) {
			*data_out_length = hdr->bytes_remaining - sizeof(OspProtocolFooter);
			*data_out = g_new0 (guint8, hdr->bytes_remaining);

			/* copy the first chunk of data */
			offset_wr = 64 - offset_rd;
			memcpy (*data_out, buffer_out + offset_rd, offset_wr);
		} else {
			g_assert_not_reached ();
		}
	}

	/* read the rest of the payload */
	payload_length = hdr->bytes_remaining - sizeof(OspProtocolFooter);
	for (i = 0; i < payload_length / 64; i++) {
		if (!g_usb_device_bulk_transfer (device, 0x81,
						 buffer_out, OSP_DEVICE_EP_SIZE,
						 &actual_length,
						 OSP_USB_TIMEOUT_MS, NULL, error))
			return FALSE;
		if (data_out != NULL) {
			memcpy (*data_out + offset_wr,
				buffer_out, OSP_DEVICE_EP_SIZE);
		}
		if (g_getenv ("SPARK_PROTOCOL_DEBUG") != NULL)
			cd_buffer_debug (CD_BUFFER_KIND_RESPONSE, buffer_out, OSP_DEVICE_EP_SIZE);
		offset_wr += 64;
	}
	offset_rd += payload_length;

	/* verify the footer is intact */
	ftr = (OspProtocolFooter *) (buffer_out + OSP_DEVICE_EP_SIZE - sizeof(OspProtocolFooter));
	if (ftr->end_bytes != GUINT32_TO_BE (0xc5c4c3c2)) {
		g_set_error_literal (error,
				     OSP_DEVICE_ERROR,
				     OSP_DEVICE_ERROR_INTERNAL,
				     "Footer invalid");
		return FALSE;
	}

	return TRUE;
}
示例#21
0
gboolean
separate_psd_export (gchar         *filename,
                     gint32         imageID,
                     gconstpointer  profile_data,
                     gsize          profile_length,
                     gconstpointer  path_data,
                     gsize          path_length,
                     gboolean       compression)
{
  int fd;
  PSDHeader header;
  PSDResResource res;
  PSDIccResource icc;

  fd = g_open (filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 00644);

  if (fd != -1)
    {
      gint32 length;
      gint32 width, height;
      gdouble xres, yres;

      width = gimp_image_width (imageID);
      height = gimp_image_height (imageID);

      /* header */
      header.signature = GUINT32_TO_BE (0x38425053);
      header.version = GUINT16_TO_BE (1);
      memset (header.reserved, 0, sizeof (header.reserved));
      header.channels = GINT16_TO_BE (4); /* C, M, Y, K, and no alpha channels */
      header.height = GINT32_TO_BE (height);
      header.width = GINT32_TO_BE (width);
      header.depth = GINT16_TO_BE (8); /* 8bit per channels */
      header.mode = GINT16_TO_BE (4); /* CMYK Mode */

      write (fd, &header, sizeof (header));

      /***** color mode data *****/
      length = 0;
      write (fd, &length, sizeof (gint32));

      /***** image resources *****/
      length = 0;

      /* resolution info */
      gimp_image_get_resolution (imageID, &xres, &yres);
      res.type = GUINT32_TO_BE (0x3842494d);
      res.id = GUINT16_TO_BE (0x03ed);
      memset (res.name, 0, 2);
      res.size = GINT32_TO_BE (16);
      res.hres = GINT32_TO_BE (xres * 65536.0);
      res.hres_unit = GINT16_TO_BE (1);
      res.width_unit = GINT16_TO_BE (1);
      res.vres = GINT32_TO_BE (yres * 65536.0);
      res.vres_unit = GINT16_TO_BE (1);
      res.height_unit = GINT16_TO_BE (1);

      length += sizeof (PSDResResource);

      /* ICC profile */
      if (profile_data)
        {
          icc.type = res.type;
          icc.id = GUINT16_TO_BE (0x040f);
          memset (icc.name, 0, 2);
          icc.size = GINT32_TO_BE (profile_length);

          length += sizeof (PSDIccResource) + profile_length;
        }

      /* path */
      if (path_data)
        length += path_length;

      /* write data... */
      length = GINT32_TO_BE (length);
      write (fd, &length, sizeof (gint32));

      write (fd, &res, sizeof (PSDResResource));

      if (profile_data)
        {
          write (fd, &icc, sizeof (PSDIccResource));
          write (fd, profile_data, profile_length);
        }

      if (path_data)
        write (fd, path_data, path_length);

      /***** layer and mask info *****/
      length = 0;
      write (fd, &length, sizeof (gint32));

      /***** image data *****/
      if (compression)
        psd_write_image_data_packbits (fd, imageID, width, height);
      else
        psd_write_image_data_raw (fd, imageID, width, height);

      close (fd);

      return TRUE;
    }

  return FALSE;
}
示例#22
0
/*!
  \brief handles a simple read result
  \param data is a pointer to a Io_Message structure
  \param func is an enum representing the action we need to handle
  */
G_MODULE_EXPORT void simple_read_hf(void * data, FuncCall func)
{
	static guint16 lastcount = 0;
	static gboolean just_starting = TRUE;
	Io_Message *message  = NULL;
	OutputData *output  = NULL;
	gint count = 0;
	gchar *tmpbuf = NULL;
	gint page = -1;
	gint canID = -1;
	gint tmpi = 0;
	gint adder = 0;
	gboolean check_header = FALSE;
	gint base_offset = 0;
	guint16 curcount = 0;
	guint8 *ptr8 = NULL;
	guint16 *ptr16 = NULL;
	Firmware_Details *firmware = NULL;
	Serial_Params *serial_params = NULL;

	ENTER();
	serial_params = (Serial_Params *)DATA_GET(global_data,"serial_params");
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	g_return_if_fail(serial_params);
	g_return_if_fail(firmware);

	message = (Io_Message *)data;
	output = (OutputData *)message->payload;
	if (firmware->capabilities & MS3_NEWSERIAL)
	{
		check_header = TRUE;
		adder = 7;
		base_offset = 3;
	}

	switch (func)
	{
		case WRITE_VERIFY:
			printf(_("MS2_WRITE_VERIFY not written yet\n"));
			break;
		case MISMATCH_COUNT:
			printf(_("MS2_MISMATCH_COUNT not written yet\n"));
			break;
		case MS1_CLOCK:
			printf(_("MS1_CLOCK not written yet\n"));
			break;
		case MS2_CLOCK:
			printf(_("MS2_CLOCK not written yet\n"));
			break;
		case NUM_REV:
			if (DATA_GET(global_data,"offline"))
				break;
			count = read_data_f(-1,&message->recv_buf,FALSE);
			if (count > adder)
			{
				ptr8 = (guchar *)message->recv_buf;
				firmware->ecu_revision=(gint)ptr8[0+base_offset];
				ecu_info_update(firmware);
			}
			break;
		case TEXT_REV:
			if (DATA_GET(global_data,"offline"))
				break;
			count = read_data_f(-1,&message->recv_buf,FALSE);
			if (count > adder)
			{
				if (check_header)
				{
					if (message->recv_buf[2] & 0x80)
					{
						MTXDBG(CRITICAL,_("TextRev read error: specifically 0X%x\n"),message->recv_buf[2]);
						flush_serial_f(serial_params->fd,BOTH);
						break;
					}
				}
				firmware->txt_rev_len = count-adder;
				firmware->text_revision = g_markup_escape_text((const gchar *)message->recv_buf+base_offset,count-adder);
				ecu_info_update(firmware);
			}
			break;
		case SIGNATURE:
			if (DATA_GET(global_data,"offline"))
				break;
			count = read_data_f(-1,&message->recv_buf,FALSE);
			if (count > adder)
			{
				if (check_header)
				{
					if (message->recv_buf[2] & 0x80)
					{
						MTXDBG(CRITICAL,_("Signature read error: specifically 0X%x\n"),message->recv_buf[2]);
						flush_serial_f(serial_params->fd,BOTH);
						break;
					}
				}
				firmware->signature_len = count-adder;
				firmware->actual_signature = g_markup_escape_text((const gchar *)message->recv_buf+base_offset,count-adder);
				ecu_info_update(firmware);
			}
			break;
		case MS1_VECONST:
		case MS2_VECONST:
			page = (GINT)DATA_GET(output->data,"page");
			canID = (GINT)DATA_GET(output->data,"canID");
			count = read_data_f(firmware->page_params[page]->length+adder,&message->recv_buf,TRUE);
			if ((count-adder) != firmware->page_params[page]->length)
				break;
			if (check_header)
			{
				if (message->recv_buf[2] & 0x80)
				{
					MTXDBG(CRITICAL,_("MS1/2_VECONST read error: specifically 0X%x\n"),message->recv_buf[2]);
					flush_serial_f(serial_params->fd,BOTH);
					break;
				}
			}
			ms_store_new_block(canID,page,0,
					((guint8 *)message->recv_buf)+base_offset,
					firmware->page_params[page]->length);
			ms_backup_current_data(canID,page);
			tmpi = (GINT)DATA_GET(global_data,"ve_goodread_count");
			DATA_SET(global_data,"ve_goodread_count",GINT_TO_POINTER(++tmpi));
			break;
		case MS1_RT_VARS:
			count = read_data_f(firmware->rtvars_size+adder,&message->recv_buf,TRUE);
			if ((count-adder) != firmware->rtvars_size)
				break;
			if (check_header)
			{
				if (message->recv_buf[2] & 0x80)
				{
					MTXDBG(CRITICAL,_("MS1_RT_VARS read error: specifically 0X%x\n"),message->recv_buf[2]);
					flush_serial_f(serial_params->fd,BOTH);
					break;
				}
			}
			ptr8 = (guchar *)message->recv_buf+base_offset;
			/* Test for MS reset */
			if (just_starting)
			{
				lastcount = ptr8[0];
				just_starting = FALSE;
			}
			/* Check for clock jump from the MS, a 
			 * jump in time from the MS clock indicates 
			 * a reset due to power and/or noise.
			 */
			if ((lastcount - ptr8[0] > 1) && \
					(lastcount - ptr8[0] != 255))
			{
				tmpi = (GINT)DATA_GET(global_data,"reset_count");
				DATA_SET(global_data,"reset_count",GINT_TO_POINTER(++tmpi));
				printf(_("ECU Reset detected!, lastcount %i, current %i\n"),lastcount,ptr8[0]);
				gdk_beep();
			}
			else
			{
				tmpi = (GINT)DATA_GET(global_data,"rt_goodread_count");
				DATA_SET(global_data,"rt_goodread_count",GINT_TO_POINTER(++tmpi));
			}
			lastcount = ptr8[0];
			/* Feed raw buffer over to post_process(void)
			 * as a void * and pass it a pointer to the new
			 * area for the parsed data...
			 */
			process_rt_vars_f(((guint8 *)message->recv_buf)+base_offset,firmware->rtvars_size);
			break;
		case MS2_RT_VARS:
			page = (GINT)DATA_GET(output->data,"page");
			canID = (GINT)DATA_GET(output->data,"canID");
			count = read_data_f(firmware->rtvars_size+adder,&message->recv_buf,TRUE);
			if ((count-adder) != firmware->rtvars_size)
				break;
			if (check_header)
			{
				if (message->recv_buf[2] & 0x80)
				{
					MTXDBG(CRITICAL,_("MS2_RT_VARS read error: specifically 0X%x\n"),message->recv_buf[2]);
					flush_serial_f(serial_params->fd,BOTH);
					break;
				}
			}
			ms_store_new_block(canID,page,0,
					((guint8 *)message->recv_buf)+base_offset,
					firmware->page_params[page]->length);
			ms_backup_current_data(canID,page);
			ptr16 = (guint16 *)message->recv_buf+base_offset;
			/* Test for MS reset */
			if (just_starting)
			{
				if (firmware->bigendian)
				{
					lastcount = GUINT16_TO_BE(ptr16[0]);
					curcount = GUINT16_TO_BE(ptr16[0]);
				}
				else
				{
					lastcount = GUINT16_TO_LE(ptr16[0]);
					curcount = GUINT16_TO_LE(ptr16[0]);
				}
				just_starting = FALSE;
			}
			else
			{
				if (firmware->bigendian)
					curcount = GUINT16_TO_BE(ptr16[0]);
				else
					curcount = GUINT16_TO_LE(ptr16[0]);
			}
			/* Check for clock jump from the MS, a 
			 * jump in time from the MS clock indicates 
			 * a reset due to power and/or noise.
			 */
			if ((lastcount - curcount > 1) && \
					(lastcount - curcount != 65535))
			{
				tmpi = (GINT)DATA_GET(global_data,"reset_count");
				DATA_SET(global_data,"reset_count",GINT_TO_POINTER(++tmpi));
				printf(_("MS2 rtvars reset detected, lastcount is %i, current %i"),lastcount,curcount);
				gdk_beep();
			}
			else
			{
				tmpi = (GINT)DATA_GET(global_data,"rt_goodread_count");
				DATA_SET(global_data,"rt_goodread_count",GINT_TO_POINTER(++tmpi));
			}
			lastcount = curcount;
			/* Feed raw buffer over to post_process(void)
			 * as a void * and pass it a pointer to the new
			 * area for the parsed data...
			 */
			process_rt_vars_f(((guint8 *)message->recv_buf)+base_offset,firmware->rtvars_size);
			break;
		case MS2_BOOTLOADER:
			printf(_("MS2_BOOTLOADER not written yet\n"));
			break;
		case MS1_GETERROR:
			DATA_SET(global_data,"forced_update",GINT_TO_POINTER(TRUE));
			DATA_SET(global_data,"force_page_change",GINT_TO_POINTER(TRUE));
			count = read_data_f(-1,&message->recv_buf,FALSE);
			if (count <= 10)
			{
				thread_update_logbar_f("error_status_view",NULL,g_strdup(_("No ECU Errors were reported....\n")),FALSE,FALSE);
				break;
			}
			if (g_utf8_validate(((gchar *)message->recv_buf)+1,count-1,NULL))
			{
				thread_update_logbar_f("error_status_view",NULL,g_strndup(((gchar *)message->recv_buf+7)+1,count-8),FALSE,FALSE);
				tmpbuf = g_strndup(((gchar *)message->recv_buf)+1,count-1);
				MTXDBG(IO_PROCESS|SERIAL_RD,_("ECU ERROR string: \"%s\"\n"),tmpbuf);
				g_free(tmpbuf);
			}
			else
				thread_update_logbar_f("error_status_view",NULL,g_strdup("The data came back as gibberish, please try again...\n"),FALSE,FALSE);
			break;
		default:
			break;
	}
	EXIT();
	return;
}
示例#23
0
/*!
 \brief ECU specifc that gets called to send a value to the ECU. 
 \param canID is the can Identifier
 \param locID is the Location ID to where this value belongs
 \param offset is the offset from the beginning of the page that this data
 refers to.
 \param size is an enumeration corresponding to how big this variable is
 \param value is the value that should be sent to the ECU At page/offset
 \param queue_update if true queues a gui update, used to prevent
 a horrible stall when doing an ECU restore or batch load...
 */
G_MODULE_EXPORT void libreems_send_to_ecu(gint canID, gint locID, gint offset, DataSize size, gint value, gboolean queue_update)
{
	static Firmware_Details *firmware = NULL;
	OutputData *output = NULL;
	guint8 *data = NULL;
	guint16 u16 = 0;
	gint16 s16 = 0;
	guint32 u32 = 0;
	gint32 s32 = 0;

	ENTER();
	if (!firmware)
		firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	g_return_if_fail(firmware);
	g_return_if_fail(offset >= 0);

	MTXDBG(SERIAL_WR,_("Sending locID %i, offset %i, value %i \n"),locID,offset,value);

	switch (size)
	{
		case MTX_CHAR:
		case MTX_S08:
		case MTX_U08:
			/*printf("8 bit var %i at offset %i\n",value,offset);*/
			break;
		case MTX_S16:
		case MTX_U16:
			/*printf("16 bit var %i at offset %i\n",value,offset);*/
			break;
		case MTX_S32:
		case MTX_U32:
			/*printf("32 bit var %i at offset %i\n",value,offset);*/
			break;
		default:
			printf(_("libreems_send_to_ecu() ERROR!!! Size undefined for variable at canID %i, offset %i\n"),locID,offset);
	}
	output = initialize_outputdata_f();
	DATA_SET(output->data,"location_id", GINT_TO_POINTER(locID));
	DATA_SET(output->data,"payload_id", GINT_TO_POINTER(REQUEST_UPDATE_BLOCK_IN_RAM));
	DATA_SET(output->data,"offset", GINT_TO_POINTER(offset));
	DATA_SET(output->data,"size", GINT_TO_POINTER(size));
	DATA_SET(output->data,"value", GINT_TO_POINTER(value));
	DATA_SET(output->data,"length", GINT_TO_POINTER(get_multiplier_f(size)));
	DATA_SET(output->data,"mode", GINT_TO_POINTER(MTX_SIMPLE_WRITE));
	/* Get memory */
	data = g_new0(guint8,get_multiplier_f(size));
	switch (size)
	{
		case MTX_CHAR:
		case MTX_U08:
			data[0] = (guint8)value;
			break;
		case MTX_S08:
			data[0] = (gint8)value;
			break;
		case MTX_U16:
			if (firmware->bigendian)
				u16 = GUINT16_TO_BE((guint16)value);
			else
				u16 = GUINT16_TO_LE((guint16)value);
			data[0] = (guint8)u16;
			data[1] = (guint8)((guint16)u16 >> 8);
			break;
		case MTX_S16:
			if (firmware->bigendian)
				s16 = GINT16_TO_BE((gint16)value);
			else
				s16 = GINT16_TO_LE((gint16)value);
			data[0] = (guint8)s16;
			data[1] = (guint8)((gint16)s16 >> 8);
			break;
		case MTX_S32:
			if (firmware->bigendian)
				s32 = GINT32_TO_BE((gint32)value);
			else
				s32 = GINT32_TO_LE((gint32)value);
			data[0] = (guint8)s32;
			data[1] = (guint8)((gint32)s32 >> 8);
			data[2] = (guint8)((gint32)s32 >> 16);
			data[3] = (guint8)((gint32)s32 >> 24);
			break;
		case MTX_U32:
			if (firmware->bigendian)
				u32 = GUINT32_TO_BE((guint32)value);
			else
				u32 = GUINT32_TO_LE((guint32)value);
			data[0] = (guint8)u32;
			data[1] = (guint8)((guint32)u32 >> 8);
			data[2] = (guint8)((guint32)u32 >> 16);
			data[3] = (guint8)((guint32)u32 >> 24);
			break;
		default:
			break;
	}
	DATA_SET_FULL(output->data,"data",(gpointer)data, g_free);
	/* Set it here otherwise there's a risk of a missed burn due to 
	 * a potential race condition in the burn checker
	 */
	libreems_set_ecu_data(canID,locID,offset,size,value);
	/* IF the packet fails, update_write_status will rollback properly */

	output->queue_update = queue_update;
	io_cmd_f(firmware->write_command,output);
	EXIT();
	return;
}
示例#24
0
void ryostkl_light_layer_key_set_effect(guint16 *key, guint effect) {
	guint16 tmp = GUINT16_FROM_BE(*key);
	tmp &= ~RYOSTKL_LIGHT_LAYER_KEY_EFFECT_MASK;
	tmp |= effect << RYOSTKL_LIGHT_LAYER_KEY_EFFECT_SHIFT;
	*key = GUINT16_TO_BE(tmp);
}
示例#25
0
void ryostkl_light_layer_key_set_breath_speed(guint16 *key, guint speed) {
	guint16 tmp = GUINT16_FROM_BE(*key);
	tmp &= ~RYOSTKL_LIGHT_LAYER_KEY_BREATH_SPEED_MASK;
	tmp |= speed << RYOSTKL_LIGHT_LAYER_KEY_BREATH_SPEED_SHIFT;
	*key = GUINT16_TO_BE(tmp);
}
示例#26
0
void
msn_write16be(char *buf, guint16 data)
{
	*(guint16 *)buf = GUINT16_TO_BE(data);
}
示例#27
0
void ryostkl_light_layer_key_set_state(guint16 *key, gboolean state) {
	guint16 tmp = GUINT16_FROM_BE(*key);
	roccat_set_bit16(&tmp, RYOSTKL_LIGHT_LAYER_KEY_BIT_STATE, state);
	*key = GUINT16_TO_BE(tmp);
}
示例#28
0
static void
send_request (GVfsAfpConnection *afp_connection)
{
  GVfsAfpConnectionPrivate *priv = afp_connection->priv;

  RequestData *req_data;
  guint32 writeOffset;
  guint8 dsi_command;

  while ((req_data = g_queue_peek_head (priv->request_queue)))
  {
    if (req_data->cancellable && g_cancellable_is_cancelled (req_data->cancellable))
    {
      if (req_data->simple)
      {
        GError *err = NULL;

        g_cancellable_set_error_if_cancelled (req_data->cancellable, &err);
        g_simple_async_result_take_error (req_data->simple, err);
        g_simple_async_result_complete (req_data->simple);
      }
      remove_first (priv->request_queue);
    }
    else
      break;
  }

  if (!req_data) {
    priv->send_loop_running = FALSE;
    return;
  }

  switch (req_data->type)
  {
    case REQUEST_TYPE_TICKLE:
      priv->write_dsi_header.flags = 0x00;
      priv->write_dsi_header.command = DSI_TICKLE;
      priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
      priv->write_dsi_header.writeOffset = 0;
      priv->write_dsi_header.totalDataLength = 0;
      priv->write_dsi_header.reserved = 0;
      break;

    case REQUEST_TYPE_COMMAND:
    {
      gsize size;
      
      switch (req_data->command->type)
      {
        case AFP_COMMAND_WRITE:
          writeOffset = 8;
          dsi_command = DSI_WRITE;
          break;
        case AFP_COMMAND_WRITE_EXT:
          writeOffset = 20;
          dsi_command = DSI_WRITE;
          break;

        default:
          writeOffset = 0;
          dsi_command = DSI_COMMAND;
          break;
      }

      priv->write_dsi_header.flags = 0x00;
      priv->write_dsi_header.command = dsi_command;
      priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
      priv->write_dsi_header.writeOffset = GUINT32_TO_BE (writeOffset);

      /* totalDataLength */
      size = g_vfs_afp_command_get_size (req_data->command);
      if (dsi_command == DSI_WRITE && req_data->command->buf)
        size += req_data->command->buf_size;
      priv->write_dsi_header.totalDataLength = GUINT32_TO_BE (size);
      
      priv->write_dsi_header.reserved = 0;
      break;
    }

    default:
      g_assert_not_reached ();
  }


  write_all_async (g_io_stream_get_output_stream (priv->conn),
                   &priv->write_dsi_header, sizeof (DSIHeader), 0,
                   NULL, write_dsi_header_cb, afp_connection);
}