bluez/tools/hciattach_tialt.c
Tedd Ho-Jeong An 0a259dd05b tools: Add SPDX License Identifier
This patch adds SPDX License Identifier and removes the license text.

-------------------------------------
       License            COUNT
-------------------------------------
 GPL-2.0-or-later     :     97
 LGPL-2.1-or-later    :     38
 GPL-2.0-only         :      2

License: GPL-2.0-or-later
   tools/l2cap-tester.c
   tools/hcisecfilter.c
   tools/ciptool.c
   tools/btsnoop.c
   tools/check-selftest.c
   tools/btpclientctl.c
   tools/hci-tester.c
   tools/hcitool.c
   tools/btiotest.c
   tools/oobtest.c
   tools/btinfo.c
   tools/hwdb.c
   tools/hciattach_bcm43xx.c
   tools/mgmt-tester.c
   tools/hex2hcd.c
   tools/hciattach_st.c
   tools/smp-tester.c
   tools/bluetooth-player.c
   tools/hciattach_tialt.c
   tools/gap-tester.c
   tools/bluemoon.c
   tools/bneptest.c
   tools/gatt-service.c
   tools/rctest.c
   tools/rfcomm-tester.c
   tools/hcieventmask.c
   tools/hciattach_ti.c
   tools/seq2bseq.c
   tools/scotest.c
   tools/bcmfw.c
   tools/hciconfig.c
   tools/btattach.c
   tools/l2ping.c
   tools/obexctl.c
   tools/l2test.c
   tools/hciattach_intel.c
   tools/hciattach.h
   tools/create-image.c
   tools/bnep-tester.c
   tools/userchan-tester.c
   tools/rfcomm.c
   tools/btmon-logger.c
   tools/hcidump.c
   tools/rtlfw.c
   tools/hciattach_qualcomm.c
   tools/btproxy.c
   tools/nokfw.c
   tools/hciattach_ath3k.c
   tools/3dsp.c
   tools/bdaddr.c
   tools/sco-tester.c
   tools/hciattach.c
   tools/amptest.c
   tools/btgatt-server.c
   tools/btgatt-client.c
   tools/cltest.c
   tools/ibeacon.c
   tools/mcaptest.c
   tools/hid2hci.c
   tools/btmgmt.c
   tools/advtest.c
   tools/eddystone.c
   tools/avtest.c
   tools/mpris-proxy.c
   tools/avinfo.c
   tools/sdptool.c
   tools/btconfig.c
   tools/update_compids.sh
   tools/parser/parser.h
   tools/parser/obex.c
   tools/parser/amp.c
   tools/parser/sdp.c
   tools/parser/tcpip.c
   tools/parser/sap.c
   tools/parser/cmtp.c
   tools/parser/avctp.c
   tools/parser/lmp.c
   tools/parser/ppp.c
   tools/parser/rfcomm.h
   tools/parser/hci.c
   tools/parser/sdp.h
   tools/parser/parser.c
   tools/parser/rfcomm.c
   tools/parser/avdtp.c
   tools/parser/avrcp.c
   tools/parser/ericsson.c
   tools/parser/hcrp.c
   tools/parser/bpa.c
   tools/parser/hidp.c
   tools/parser/bnep.c
   tools/parser/capi.c
   tools/parser/att.c
   tools/parser/l2cap.c
   tools/parser/smp.c
   tools/parser/csr.c
   tools/parser/l2cap.h
   tools/parse_companies.pl

License: LGPL-2.1-or-later
   tools/test-runner.c
   tools/btpclient.c
   tools/meshctl.c
   tools/mesh-cfgclient.c
   tools/mesh/model.h
   tools/mesh/util.h
   tools/mesh/config-model.h
   tools/mesh/cfgcli.h
   tools/mesh/mesh-db.c
   tools/mesh/mesh-db.h
   tools/mesh/keys.c
   tools/mesh/util.c
   tools/mesh/agent.h
   tools/mesh/remote.c
   tools/mesh/keys.h
   tools/mesh/agent.c
   tools/mesh/cfgcli.c
   tools/mesh/remote.h
   tools/mesh-gatt/prov.c
   tools/mesh-gatt/util.h
   tools/mesh-gatt/prov.h
   tools/mesh-gatt/net.c
   tools/mesh-gatt/util.c
   tools/mesh-gatt/prov-db.h
   tools/mesh-gatt/crypto.c
   tools/mesh-gatt/crypto.h
   tools/mesh-gatt/gatt.c
   tools/mesh-gatt/config-server.c
   tools/mesh-gatt/keys.h
   tools/mesh-gatt/onoff-model.c
   tools/mesh-gatt/net.h
   tools/mesh-gatt/gatt.h
   tools/mesh-gatt/node.c
   tools/mesh-gatt/config-client.c
   tools/mesh-gatt/mesh-net.h
   tools/mesh-gatt/node.h
   tools/mesh-gatt/onoff-model.h
   tools/mesh-gatt/prov-db.c

License: GPL-2.0-only
   tools/obex-server-tool.c
   tools/obex-client-tool.c
2020-09-29 14:37:23 -07:00

232 lines
5.6 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2005-2010 Marcel Holtmann <marcel@holtmann.org>
*
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <syslog.h>
#include <termios.h>
#include <time.h>
#include <poll.h>
#include <sys/time.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
#include "lib/hci_lib.h"
#include "hciattach.h"
#define FAILIF(x, args...) do { \
if (x) { \
fprintf(stderr, ##args); \
return -1; \
} \
} while(0)
typedef struct {
uint8_t uart_prefix;
hci_event_hdr hci_hdr;
evt_cmd_complete cmd_complete;
uint8_t status;
uint8_t data[16];
} __attribute__((packed)) command_complete_t;
static int read_command_complete(int fd, unsigned short opcode, unsigned char len) {
command_complete_t resp;
/* Read reply. */
FAILIF(read_hci_event(fd, (unsigned char *)&resp, sizeof(resp)) < 0,
"Failed to read response");
/* Parse speed-change reply */
FAILIF(resp.uart_prefix != HCI_EVENT_PKT,
"Error in response: not an event packet, but 0x%02x!\n",
resp.uart_prefix);
FAILIF(resp.hci_hdr.evt != EVT_CMD_COMPLETE, /* event must be event-complete */
"Error in response: not a cmd-complete event, "
"but 0x%02x!\n", resp.hci_hdr.evt);
FAILIF(resp.hci_hdr.plen < 4, /* plen >= 4 for EVT_CMD_COMPLETE */
"Error in response: plen is not >= 4, but 0x%02x!\n",
resp.hci_hdr.plen);
/* cmd-complete event: opcode */
FAILIF(resp.cmd_complete.opcode != (uint16_t)opcode,
"Error in response: opcode is 0x%04x, not 0x%04x!",
resp.cmd_complete.opcode, opcode);
return resp.status == 0 ? 0 : -1;
}
typedef struct {
uint8_t uart_prefix;
hci_command_hdr hci_hdr;
uint32_t speed;
} __attribute__((packed)) texas_speed_change_cmd_t;
static int texas_change_speed(int fd, uint32_t speed)
{
return 0;
}
static int texas_load_firmware(int fd, const char *firmware) {
int fw = open(firmware, O_RDONLY);
fprintf(stdout, "Opening firmware file: %s\n", firmware);
FAILIF(fw < 0,
"Could not open firmware file %s: %s (%d).\n",
firmware, strerror(errno), errno);
fprintf(stdout, "Uploading firmware...\n");
do {
/* Read each command and wait for a response. */
unsigned char data[1024];
unsigned char cmdp[1 + sizeof(hci_command_hdr)];
hci_command_hdr *cmd = (hci_command_hdr *)(cmdp + 1);
int nr;
nr = read(fw, cmdp, sizeof(cmdp));
if (!nr)
break;
FAILIF(nr != sizeof(cmdp), "Could not read H4 + HCI header!\n");
FAILIF(*cmdp != HCI_COMMAND_PKT, "Command is not an H4 command packet!\n");
FAILIF(read(fw, data, cmd->plen) != cmd->plen,
"Could not read %d bytes of data for command with opcode %04x!\n",
cmd->plen,
cmd->opcode);
{
int nw;
#if 0
fprintf(stdout, "\topcode 0x%04x (%d bytes of data).\n",
cmd->opcode,
cmd->plen);
#endif
struct iovec iov_cmd[2];
iov_cmd[0].iov_base = cmdp;
iov_cmd[0].iov_len = sizeof(cmdp);
iov_cmd[1].iov_base = data;
iov_cmd[1].iov_len = cmd->plen;
nw = writev(fd, iov_cmd, 2);
FAILIF(nw != (int) sizeof(cmd) + cmd->plen,
"Could not send entire command (sent only %d bytes)!\n",
nw);
}
/* Wait for response */
if (read_command_complete(fd,
cmd->opcode,
cmd->plen) < 0) {
return -1;
}
} while(1);
fprintf(stdout, "Firmware upload successful.\n");
close(fw);
return 0;
}
int texasalt_init(int fd, int speed, struct termios *ti)
{
struct timespec tm = {0, 50000};
char cmd[4];
unsigned char resp[100]; /* Response */
int n;
memset(resp,'\0', 100);
/* It is possible to get software version with manufacturer specific
HCI command HCI_VS_TI_Version_Number. But the only thing you get more
is if this is point-to-point or point-to-multipoint module */
/* Get Manufacturer and LMP version */
cmd[0] = HCI_COMMAND_PKT;
cmd[1] = 0x01;
cmd[2] = 0x10;
cmd[3] = 0x00;
do {
n = write(fd, cmd, 4);
if (n < 0) {
perror("Failed to write init command (READ_LOCAL_VERSION_INFORMATION)");
return -1;
}
if (n < 4) {
fprintf(stderr, "Wanted to write 4 bytes, could only write %d. Stop\n", n);
return -1;
}
/* Read reply. */
if (read_hci_event(fd, resp, 100) < 0) {
perror("Failed to read init response (READ_LOCAL_VERSION_INFORMATION)");
return -1;
}
/* Wait for command complete event for our Opcode */
} while (resp[4] != cmd[1] && resp[5] != cmd[2]);
/* Verify manufacturer */
if ((resp[11] & 0xFF) != 0x0d)
fprintf(stderr,"WARNING : module's manufacturer is not Texas Instrument\n");
/* Print LMP version */
fprintf(stderr, "Texas module LMP version : 0x%02x\n", resp[10] & 0xFF);
/* Print LMP subversion */
{
unsigned short lmp_subv = resp[13] | (resp[14] << 8);
unsigned short brf_chip = (lmp_subv & 0x7c00) >> 10;
static const char *c_brf_chip[8] = {
"unknown",
"unknown",
"brf6100",
"brf6150",
"brf6300",
"brf6350",
"unknown",
"wl1271"
};
char fw[100];
fprintf(stderr, "Texas module LMP sub-version : 0x%04x\n", lmp_subv);
fprintf(stderr,
"\tinternal version freeze: %d\n"
"\tsoftware version: %d\n"
"\tchip: %s (%d)\n",
lmp_subv & 0x7f,
((lmp_subv & 0x8000) >> (15-3)) | ((lmp_subv & 0x380) >> 7),
((brf_chip > 7) ? "unknown" : c_brf_chip[brf_chip]),
brf_chip);
sprintf(fw, "/etc/firmware/%s.bin", c_brf_chip[brf_chip]);
texas_load_firmware(fd, fw);
texas_change_speed(fd, speed);
}
nanosleep(&tm, NULL);
return 0;
}