2011-04-10 23:45:19 +03:00
|
|
|
/*
|
|
|
|
* lib/atnet.c - Access functions library for network proxy
|
|
|
|
*
|
|
|
|
* Written 2011 by Werner Almesberger
|
|
|
|
* Copyright 2011 Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
#include "netio.h"
|
|
|
|
|
|
|
|
#include "driver.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_PORT "5440"
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc {
|
|
|
|
struct netio *netio;
|
|
|
|
int error;
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
char *spec;
|
2011-04-12 15:45:34 +03:00
|
|
|
char reply[1000];
|
|
|
|
};
|
2011-04-10 23:45:19 +03:00
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int dialog_vsend(struct atnet_dsc *dsc, const char *fmt, va_list ap)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
|
|
|
va_list ap2;
|
|
|
|
char *buf;
|
2011-04-12 15:32:26 +03:00
|
|
|
int n, res;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
|
|
|
va_copy(ap2, ap);
|
|
|
|
n = vsnprintf(NULL, 0, fmt, ap2);
|
|
|
|
|
|
|
|
buf = malloc(n+1);
|
|
|
|
if (!buf) {
|
|
|
|
perror("malloc");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vsprintf(buf, fmt, ap);
|
|
|
|
|
|
|
|
buf[n] = '\n';
|
2011-04-12 15:45:34 +03:00
|
|
|
res = netio_write(dsc->netio, buf, n+1);
|
2011-04-12 15:32:26 +03:00
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return res < 0 ? -1 : 0;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int dialog_send(struct atnet_dsc *dsc, const char *fmt, ...)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2011-04-12 15:45:34 +03:00
|
|
|
res = dialog_vsend(dsc, fmt, ap);
|
2011-04-10 23:45:19 +03:00
|
|
|
va_end(ap);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int dialog_recv(struct atnet_dsc *dsc)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
n = netio_read_until(dsc->netio,
|
|
|
|
"\n", dsc->reply, sizeof(dsc->reply)-1, NULL);
|
2011-04-10 23:45:19 +03:00
|
|
|
if (n < 0)
|
|
|
|
return -1;
|
2011-04-12 15:45:34 +03:00
|
|
|
dsc->reply[n] = 0;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
return dsc->reply[0] == '+' ? 0 : -1;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int dialog(struct atnet_dsc *dsc, const char *fmt, ...)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2011-04-12 15:45:34 +03:00
|
|
|
res = dialog_vsend(dsc, fmt, ap);
|
2011-04-10 23:45:19 +03:00
|
|
|
va_end(ap);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
return dialog_recv(dsc);
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- error handling ---------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int atnet_error(void *handle)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
|
|
|
|
|
|
|
return dsc->error;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int atnet_clear_error(void *handle)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
int ret;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
ret = dsc->error;
|
|
|
|
dsc->error = 0;
|
2011-04-10 23:45:19 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- open/close -------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void *atnet_open(const char *arg)
|
|
|
|
{
|
|
|
|
char *host = NULL, *comma;
|
|
|
|
const char *port = DEFAULT_PORT;
|
|
|
|
struct addrinfo *addrs;
|
|
|
|
const struct addrinfo *addr;
|
|
|
|
static struct addrinfo hint = { .ai_socktype = SOCK_STREAM };
|
|
|
|
int res, s;
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
|
|
|
if (arg) {
|
|
|
|
host = strdup(arg);
|
|
|
|
if (!host) {
|
|
|
|
perror("strdup");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
comma = strchr(host, ',');
|
|
|
|
if (comma) {
|
|
|
|
*comma = 0;
|
|
|
|
port = comma+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = getaddrinfo(arg && *host ? host : NULL, port, &hint, &addrs);
|
|
|
|
if (res < 0) {
|
|
|
|
fprintf(stderr, "%s: %s\n", arg, gai_strerror(res));
|
|
|
|
free(host);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
free(host);
|
|
|
|
|
|
|
|
for (addr = addrs; addr; addr = addr->ai_next) {
|
|
|
|
s = socket(addr->ai_family, addr->ai_socktype,
|
|
|
|
addr->ai_protocol);
|
|
|
|
if (s < 0)
|
|
|
|
continue;
|
|
|
|
if (connect(s, addr->ai_addr, addr->ai_addrlen) >= 0)
|
|
|
|
break;
|
|
|
|
close(s);
|
|
|
|
}
|
|
|
|
if (!addr) {
|
|
|
|
perror(arg);
|
|
|
|
freeaddrinfo(addrs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo(addrs);
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
dsc = malloc(sizeof(*dsc));
|
|
|
|
if (!dsc) {
|
|
|
|
perror("malloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
dsc->netio = netio_open(s);
|
|
|
|
if (!dsc->netio) {
|
|
|
|
free(dsc);
|
2011-04-10 23:45:19 +03:00
|
|
|
return NULL;
|
2011-04-12 15:45:34 +03:00
|
|
|
}
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog_recv(dsc) < 0) {
|
|
|
|
netio_close(dsc->netio);
|
|
|
|
free(dsc);
|
2011-04-10 23:45:19 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
dsc->error = 0;
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
dsc->spec = NULL;
|
2011-04-12 15:45:34 +03:00
|
|
|
*dsc->reply = 0;
|
|
|
|
|
|
|
|
return dsc;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static void atnet_close(void *handle)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
netio_close(dsc->netio);
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
free(dsc->spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- driver specification ---------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static const char *atnet_driver_spec(void *handle)
|
|
|
|
{
|
|
|
|
struct atnet_dsc *dsc = handle;
|
|
|
|
|
|
|
|
if (dialog(dsc, "SPEC") < 0) {
|
|
|
|
dsc->error = 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
free(dsc->spec);
|
|
|
|
dsc->spec = strdup(dsc->reply+1);
|
|
|
|
if (!dsc->spec) {
|
|
|
|
perror("strdup");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return dsc->spec;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- device mode ------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static void atnet_reset(void *handle)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog(dsc, "RESET") < 0)
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static void atnet_reset_rf(void *handle)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog(dsc, "RESET_RF") < 0)
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static void atnet_test_mode(void *handle)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog(dsc, "TEST") < 0)
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static void atnet_slp_tr(void *handle, int on)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog(dsc, "SLP_TR %d", on) < 0)
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- register access --------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static void atnet_reg_write(void *handle, uint8_t reg, uint8_t value)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog(dsc, "SET 0x%02x 0x%02x", reg, value) < 0)
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static uint8_t atnet_reg_read(void *handle, uint8_t reg)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
unsigned long value;
|
|
|
|
char *end;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog(dsc, "GET 0x%02x", reg) < 0) {
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2011-04-12 15:45:34 +03:00
|
|
|
value = strtoul(dsc->reply+1, &end, 0);
|
2011-04-10 23:45:19 +03:00
|
|
|
if (*end || value > 255) {
|
2011-04-12 15:45:34 +03:00
|
|
|
fprintf(stderr, "invalid response \"%s\"\n", dsc->reply+1);
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- frame buffer access ----------------------------------------------- */
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static void atnet_buf_write(void *handle, const void *buf, int size)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
char tmp[20];
|
|
|
|
int n;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
n = snprintf(tmp, sizeof(tmp), "WRITE %d ", size);
|
|
|
|
assert(n < sizeof(tmp));
|
2011-04-12 15:45:34 +03:00
|
|
|
if (netio_write(dsc->netio, tmp, n) < 0) {
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (netio_write(dsc->netio, buf, size) < 0) {
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (netio_write(dsc->netio, "\n", 1) < 0) {
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog_recv(dsc) < 0)
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int atnet_buf_read(void *handle, void *buf, int size)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
uint8_t tmp[200];
|
|
|
|
int n, got = 0;
|
|
|
|
unsigned long len = 0;
|
|
|
|
char *end;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return -1;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog_send(dsc, "READ") < 0)
|
2011-04-10 23:45:19 +03:00
|
|
|
goto fail;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
n = netio_read_until(dsc->netio, " ", tmp, sizeof(tmp)-1, NULL);
|
2011-04-11 16:40:44 +03:00
|
|
|
if (n < 0)
|
|
|
|
goto fail;
|
|
|
|
tmp[n] = 0;
|
2011-04-10 23:45:19 +03:00
|
|
|
if (*tmp == '-') {
|
2011-04-11 16:40:44 +03:00
|
|
|
fprintf(stderr, "%s ", tmp+1);
|
2011-04-12 15:45:34 +03:00
|
|
|
n = netio_read_until(dsc->netio,
|
|
|
|
"\n", tmp, sizeof(tmp)-1, NULL);
|
2011-04-11 16:40:44 +03:00
|
|
|
if (n >= 0) {
|
|
|
|
tmp[n] = 0;
|
|
|
|
fprintf(stderr, "%s\n", tmp);
|
|
|
|
}
|
2011-04-10 23:45:19 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-04-11 16:40:44 +03:00
|
|
|
if (*tmp != '+' || n < 2) /* +0<spc> */
|
2011-04-10 23:45:19 +03:00
|
|
|
goto invalid;
|
|
|
|
len = strtoul(tmp+1, &end, 0);
|
2011-04-11 16:40:44 +03:00
|
|
|
if (*end)
|
2011-04-10 23:45:19 +03:00
|
|
|
goto invalid;
|
|
|
|
if (len > size) {
|
|
|
|
fprintf(stderr, "buffer overflow\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
got = netio_read(dsc->netio, buf, len);
|
2011-04-10 23:45:19 +03:00
|
|
|
if (got < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (netio_getc(dsc->netio, tmp) < 0)
|
2011-04-10 23:45:19 +03:00
|
|
|
goto fail;
|
|
|
|
if (*tmp == '\n')
|
|
|
|
return len;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
fprintf(stderr, "invalid reponse\n");
|
|
|
|
fail:
|
2011-04-12 15:45:34 +03:00
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- RF interrupt ------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int atnet_interrupt(void *handle)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
unsigned long value;
|
|
|
|
char *end;
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dsc->error)
|
2011-04-10 23:45:19 +03:00
|
|
|
return -1;
|
2011-04-12 15:45:34 +03:00
|
|
|
if (dialog(dsc, "POLL") < 0) {
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2011-04-12 15:45:34 +03:00
|
|
|
value = strtoul(dsc->reply+1, &end, 0);
|
2011-04-10 23:45:19 +03:00
|
|
|
if (*end || value > 1) {
|
2011-04-12 15:45:34 +03:00
|
|
|
fprintf(stderr, "invalid response \"%s\"\n", dsc->reply+1);
|
|
|
|
dsc->error = 1;
|
2011-04-10 23:45:19 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- CLKM handling ----------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2011-04-12 15:45:34 +03:00
|
|
|
static int atnet_set_clkm(void *handle, int mhz)
|
2011-04-10 23:45:19 +03:00
|
|
|
{
|
2011-04-12 15:45:34 +03:00
|
|
|
struct atnet_dsc *dsc = handle;
|
2011-04-10 23:45:19 +03:00
|
|
|
|
2011-05-18 06:20:00 +03:00
|
|
|
return dialog(dsc, "CLKM %d", mhz) == 0;
|
2011-04-10 23:45:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- driver interface -------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
struct atrf_driver atnet_driver = {
|
|
|
|
.name = "net",
|
|
|
|
.open = atnet_open,
|
|
|
|
.close = atnet_close,
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
.driver_spec = atnet_driver_spec,
|
2011-04-10 23:45:19 +03:00
|
|
|
.error = atnet_error,
|
|
|
|
.clear_error = atnet_clear_error,
|
|
|
|
.reset = atnet_reset,
|
|
|
|
.reset_rf = atnet_reset_rf,
|
|
|
|
.test_mode = atnet_test_mode,
|
|
|
|
.slp_tr = atnet_slp_tr,
|
|
|
|
.set_clkm = atnet_set_clkm,
|
|
|
|
.reg_write = atnet_reg_write,
|
|
|
|
.reg_read = atnet_reg_read,
|
|
|
|
.buf_write = atnet_buf_write,
|
|
|
|
.buf_read = atnet_buf_read,
|
|
|
|
.interrupt = atnet_interrupt,
|
|
|
|
};
|