Esempio n. 1
0
ow_ret_val_t ow_init(void)
{
    ow_ret_val_t res;
    ow_scratchpad_t sp;

    switch (read_device_id())
    {
        case 0x0001:
            ow_sensors = sensors_brd0001;
            ow_num_sensors = sizeof(sensors_brd0001) / sizeof(ow_device_t);
          break;
        case 0x0002:
            ow_sensors = sensors_brd0002;
            ow_num_sensors = (int8_t)sizeof(sensors_brd0002) / sizeof(ow_device_t);
          break;
    }

    int8_t num_sensors = ow_num_sensors;
    do
    {
        res = ow_write_scratchpad(&(ow_sensors[num_sensors]), &sp);
        ow_convert_temp_async(&(ow_sensors[num_sensors]));
        if (res != OW_RET_OK)
            return res;
    } while(--num_sensors >= 0);

    return OW_RET_OK;
}
Esempio n. 2
0
static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,
								char *pinbuf)
{
	uint16_t vendor, product;
	bdaddr_t sba, dba;
	char src_addr[18], dst_addr[18];

	adapter_get_address(adapter, &sba);
	device_get_address(device, &dba);
	ba2str(&sba, src_addr);
	ba2str(&dba, dst_addr);

	if (0 == read_device_id(src_addr, dst_addr, NULL, &vendor, &product,
									NULL)) {
		if (vendor == 0x057e && product == 0x0306) {
			DBG("Forcing fixed pin on detected wiimote %s", dst_addr);
			memcpy(pinbuf, &sba, 6);
			return 6;
		}
	}

	return 0;
}
Esempio n. 3
0
static int hidp_add_connection(const struct input_device *idev,
				const struct input_conn *iconn)
{
	struct hidp_connadd_req *req;
	struct fake_hid *fake_hid;
	struct fake_input *fake;
	sdp_record_t *rec;
	char src_addr[18], dst_addr[18];
	int err;

	req = g_new0(struct hidp_connadd_req, 1);
	req->ctrl_sock = g_io_channel_unix_get_fd(iconn->ctrl_io);
	req->intr_sock = g_io_channel_unix_get_fd(iconn->intr_io);
	req->flags     = 0;
	req->idle_to   = iconn->timeout;

	ba2str(&idev->src, src_addr);
	ba2str(&idev->dst, dst_addr);

	rec = fetch_record(src_addr, dst_addr, idev->handle);
	if (!rec) {
		error("Rejected connection from unknown device %s", dst_addr);
		err = -EPERM;
		goto cleanup;
	}

	extract_hid_record(rec, req);
	sdp_record_free(rec);

	read_device_id(src_addr, dst_addr, NULL,
				&req->vendor, &req->product, &req->version);

	fake_hid = get_fake_hid(req->vendor, req->product);
	if (fake_hid) {
		fake = g_new0(struct fake_input, 1);
		fake->connect = fake_hid_connect;
		fake->disconnect = fake_hid_disconnect;
		fake->priv = fake_hid;
		err = fake_hid_connadd(fake, iconn->intr_io, fake_hid);
		goto cleanup;
	}

	if (idev->name)
		strncpy(req->name, idev->name, sizeof(req->name) - 1);

	/* Encryption is mandatory for keyboards */
	if (req->subclass & 0x40) {
		err = bt_acl_encrypt(&idev->src, &idev->dst, encrypt_completed, req);
		if (err == 0) {
			/* Waiting async encryption */
			return 0;
		} else if (err != -EALREADY) {
			error("bt_acl_encrypt(): %s(%d)", strerror(-err), -err);
			goto cleanup;
		}
	}

	err = ioctl_connadd(req);

cleanup:
	free(req->rd_data);
	g_free(req);

	return err;
}
Esempio n. 4
0
uint16_t flash_reprogram(uint16_t handle) {
  // Determine file size.
  uint32_t data_size = file_size(handle);

  // Check device ID.
  uint32_t id = read_device_id();
  printf("ID: 0x%08lx\n", id);
  if (id != EXPECTED_DEVICE_ID) {
    return FLASH_PROGRAM_ID_MISMATCH;
  }

  // Erase enough sectors to fit the new configuration file.
#if defined(DEBUG)
  printf_P(PSTR("Erasing chip\n"));
#endif  // defined (DEBUG)
  // Set write enable.
  write_enable();
  // Start block erase.
  chip_erase();
  // Make sure WIP bit is set.
  if (!(read_status_reg() & (1 << STATUS_REG_WIP))) {
    return FLASH_PROGRAM_ERASE_START_ERROR;
  }
  // Wait for WIP = 0.
  // TODO: add timeout.
  while (read_status_reg() & (1 << STATUS_REG_WIP));

  // Write the new data to flash.
  char file_buf[PAGE_SIZE];
  for (uint32_t offset = 0; offset < data_size; offset += PAGE_SIZE) {
    // Read the file.
    uint16_t size_read = file_read(handle, file_buf, PAGE_SIZE);
    if (size_read < PAGE_SIZE && size_read != offset - data_size) {
      return FLASH_PROGRAM_FILE_READ_ERROR;
    }

    bool page_empty = true;
    for (uint16_t page_offset = 0; page_offset < size_read; ++page_offset) {
      if (file_buf[page_offset] != UNINITIALIZED_MEMORY_VALUE) {
        page_empty = false;
        break;
      }
    }

    if (page_empty) {
#if defined(DEBUG)
      printf_P(PSTR("No data at 0x%08lx\n"), offset);
#endif  // defined(DEBUG)
      continue;
    }

    // Obtain a 32-bit checksum.
    uint32_t checksum = get_checksum(file_buf, size_read);

    // Program a |PAGE_SIZE| page of the flash.
    write_enable();
#if defined(DEBUG)
    printf_P(PSTR("Programming data at 0x%08lx\n"), offset);
#endif  // defined(DEBUG)
    page_program(offset, file_buf, size_read);

    // Make sure WIP bit is set.
    if (!(read_status_reg() & (1 << STATUS_REG_WIP))) {
      return FLASH_PROGRAM_WRITE_START_ERROR;
    }
    // Wait for programming to finish.
    // TODO: add timeout.
    while (read_status_reg() & (1 << STATUS_REG_WIP));

    // Read back and check the checksum.
    read_data(offset, file_buf, size_read);
    uint32_t new_checksum = get_checksum(file_buf, size_read);

    if (checksum != new_checksum) {
      return FLASH_PROGRAM_WRITE_VERIFY_ERROR;
    }
  }

  return FLASH_PROGRAM_SUCCESS;
}