aura  0.1
 All Data Structures Functions Variables Modules Pages
susb-set-serial.c
1 #include <aura/aura.h>
2 #include <unistd.h>
3 #define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8))
4 
5 
6 void write_serial(struct aura_node *node, const char *str)
7 {
8  int ret;
9  uint16_t *data = malloc(32);
10  int i = 0;
11  struct aura_buffer *retbuf;
12 
13  data[i++] = USB_STRING_DESCRIPTOR_HEADER(strlen(str));
14  do {
15  data[i++] = *str++;
16  } while (*str);
17 
18  ret = aura_call(node, "set_serial", &retbuf, 0, 0, data);
19  printf("Serial number written with result %d, replug the device\n", ret);
20  aura_buffer_release(retbuf);
21  free(data);
22 }
23 
24 int main(int argc, const char **argv) {
25 
26  slog_init(NULL, 88);
27 
28  struct aura_node *n = aura_open("simpleusb", "simpleusbconfigs/pw-ctl.conf");
29  if (!n) {
30  printf("err\n");
31  return -1;
32  }
33 
34  aura_wait_status(n, AURA_STATUS_ONLINE);
35 
36  write_serial(n, argv[1]);
37 
38  aura_close(n);
39  return 0;
40 }
void aura_wait_status(struct aura_node *node, int status)
Definition: aura.c:607
int aura_call(struct aura_node *node, const char *name, struct aura_buffer **retbuf,...)
Definition: aura.c:666
struct aura_node * aura_open(const char *name, const char *opts)
Definition: aura.c:34
void aura_buffer_release(struct aura_buffer *buf)
Definition: buffer.c:80
void aura_close(struct aura_node *node)
Definition: aura.c:102
char * data
Definition: aura.h:347