Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions common/data/virtmodem.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,22 +325,16 @@ static int gopen(const char *command)
to be /dev/gnokii etc. ) */
static int VM_PtySetup(const char *bindir)
{
char mgnokiidev[200];
char mgnokiidev[256];

if (UseSTDIO) {
PtyRDFD = STDIN_FILENO;
PtyWRFD = STDOUT_FILENO;
return (0);
}

if (bindir) {
strncpy(mgnokiidev, bindir, sizeof(mgnokiidev));
strncat(mgnokiidev, "/", sizeof(mgnokiidev) - strlen(mgnokiidev) - 1);
} else {
mgnokiidev[0] = 0;
}

strncat(mgnokiidev, "mgnokiidev", sizeof(mgnokiidev) - strlen(mgnokiidev) - 1);
snprintf(mgnokiidev, sizeof(mgnokiidev), "%s%smgnokiidev",
bindir ? bindir : "", bindir ? "/" : "");

if (access(mgnokiidev, X_OK) != 0) {
fprintf(stderr, _("Cannot access %s, check the bindir in your config file!\n"), mgnokiidev);
Expand Down
26 changes: 21 additions & 5 deletions common/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const static gn_device_ops _bluetooth_ops = {
bluetooth_select,
bluetooth_read,
bluetooth_write,
bluetooth_getfd,
};
# define bluetooth_ops &_bluetooth_ops
#else
Expand Down Expand Up @@ -56,6 +57,7 @@ const static gn_device_ops _irda_ops = {
irda_select,
irda_read,
irda_write,
irda_getfd,
};
# define irda_ops &_irda_ops
#else
Expand All @@ -69,6 +71,7 @@ const static gn_device_ops _serial_ops = {
serial_select,
serial_read,
serial_write,
serial_getfd,
serial_nreceived,
serial_flush,
serial_changespeed,
Expand All @@ -84,6 +87,7 @@ const static gn_device_ops _phonet_ops = {
socketphonet_select,
socketphonet_read,
socketphonet_write,
socketphonet_getfd,
};
# define phonet_ops &_phonet_ops
#else
Expand All @@ -98,6 +102,7 @@ const static gn_device_ops _tcp_ops = {
tcp_select,
tcp_read,
tcp_write,
tcp_getfd,
};
# define tcp_ops &_tcp_ops
#else
Expand All @@ -111,12 +116,22 @@ const static gn_device_ops _tekram_ops = {
tekram_select,
tekram_read,
tekram_write,
tekram_getfd,
NULL,
NULL,
tekram_changespeed,
tekram_setdtrrts,
};
#define tekram_ops &_tekram_ops

GNOKII_API int device_getfd(struct gn_statemachine *state)
{
return state->device.fd;
gn_device *device = &state->device;

if (device->ops->getfd && device->instance)
return device->ops->getfd(device->instance);

return -1;
}

int device_open(int with_odd_parity, int with_async,
Expand Down Expand Up @@ -171,12 +186,11 @@ int device_open(int with_odd_parity, int with_async,
return 0;

device->type = device_type;
device->fd = *(int *)(device->instance);

/*
* handle config file connect_script:
*/
if (device_script(device->fd, 1, state)) {
if (device_script(device_getfd(state), 1, state)) {
dprintf("gnokii open device: connect_script failure\n");
device_close(state);
return 0;
Expand All @@ -189,19 +203,21 @@ void device_close(struct gn_statemachine *state)
{
gn_device *device = &state->device;

if (!device->instance)
return;

dprintf("device: closing device\n");

/*
* handle config file disconnect_script:
*/
if (device_script(device->fd, 0, state))
if (device_script(device_getfd(state), 0, state))
dprintf("gnokii device close: disconnect_script failure\n");

device->ops->close(device->instance);
free(device->instance);
device->instance = NULL;
device->type = GN_CT_NONE;
device->fd = -1;
}

void device_setdtrrts(int dtr, int rts, struct gn_statemachine *state)
Expand Down
3 changes: 1 addition & 2 deletions common/devices/dku2libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ void* fbusdku2usb_open(gn_config *cfg, int with_odd_parity, int with_async)
if (iface) {
if (usbfbus_connect_request(iface))
return iface;
else
free(iface);
usbfbus_free_interfaces(iface);
}

return NULL;
Expand Down
6 changes: 6 additions & 0 deletions common/devices/osxbluetooth.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,9 @@ void bluetooth_close(void *instance)
GnokiiOSXBluetooth *q = instance;
[q release];
}

int bluetooth_getfd(void *instance)
{
/* FIXME: Any way to get a file descriptor from IOBluetooth object? */
return -1;
}
5 changes: 5 additions & 0 deletions common/devices/socketphonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ void socketphonet_close(void *instance)
close(*(int *)instance);
}

int socketphonet_getfd(void *instance)
{
return *(int *)instance;
}


size_t socketphonet_read(void *instance, __ptr_t buf, size_t nbytes)
{
Expand Down
5 changes: 5 additions & 0 deletions common/devices/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ void tcp_close(void *instance)
close(*(int *)instance);
}

int tcp_getfd(void *instance)
{
return *(int *)instance;
}

extern int unix_select(int fd, struct timeval *timeout);

int tcp_select(void *instance, struct timeval *timeout)
Expand Down
40 changes: 25 additions & 15 deletions common/devices/tekram.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,27 @@ void tekram_close(void *instance)
serial_close(instance);
}

void tekram_reset(void *instance)
int tekram_select(void *instance, struct timeval *timeout)
{
return serial_select(instance, timeout);
}

size_t tekram_read(void *instance, __ptr_t buf, size_t nbytes)
{
return serial_read(instance, buf, nbytes);
}

size_t tekram_write(void *instance, const __ptr_t buf, size_t n)
{
return serial_write(instance, buf, n);
}

int tekram_getfd(void *instance)
{
return serial_getfd(instance);
}

static void tekram_reset(void *instance)
{
serial_setdtrrts(instance, 0, 0);
usleep(50000);
Expand All @@ -52,7 +72,7 @@ void tekram_reset(void *instance)
serial_changespeed(instance, 9600);
}

void tekram_changespeed(void *instance, int speed)
gn_error tekram_changespeed(void *instance, int speed)
{
unsigned char speedbyte;
switch (speed) {
Expand All @@ -69,20 +89,10 @@ void tekram_changespeed(void *instance, int speed)
serial_write(instance, &speedbyte, 1);
usleep(100000);
serial_setdtrrts(instance, 1, 1);
serial_changespeed(instance, speed);
return serial_changespeed(instance, speed);
}

size_t tekram_read(void *instance, __ptr_t buf, size_t nbytes)
void tekram_setdtrrts(void *instance, int dtr, int rts)
{
return serial_read(instance, buf, nbytes);
}

size_t tekram_write(void *instance, const __ptr_t buf, size_t n)
{
return serial_write(instance, buf, n);
}

int tekram_select(void *instance, struct timeval *timeout)
{
return serial_select(instance, timeout);
return serial_setdtrrts(instance, dtr, rts);
}
5 changes: 5 additions & 0 deletions common/devices/unixbluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ void bluetooth_close(void *instance)
close(*(int *)instance);
}

int bluetooth_getfd(void *instance)
{
return *(int *)instance;
}

size_t bluetooth_write(void *instance, const __ptr_t bytes, size_t size)
{
return write(*(int *)instance, bytes, size);
Expand Down
5 changes: 5 additions & 0 deletions common/devices/unixirda.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ void irda_close(void *instance)
close(fd);
}

int irda_getfd(void *instance)
{
return *(int *)instance;
}

size_t irda_write(void *instance, const __ptr_t bytes, size_t size)
{
return send(*(int *)instance, bytes, size, 0);
Expand Down
21 changes: 13 additions & 8 deletions common/devices/unixserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,13 @@ void* serial_open(gn_config *cfg, int with_odd_parity, int with_async)
ret = tcflush(data->fd, TCIFLUSH);
if (ret == -1) {
perror("Gnokii serial_opendevice: tcflush");
serial_close(data);
return NULL;
goto bail;
}

ret = tcsetattr(data->fd, TCSANOW, &tp);
if (ret == -1) {
perror("Gnokii serial_opendevice: tcsetattr");
serial_close(data);
return NULL;
goto bail;
}

if (serial_changespeed(data, cfg->serial_baudrate) != GN_ERR_NONE)
Expand All @@ -178,8 +176,7 @@ void* serial_open(gn_config *cfg, int with_odd_parity, int with_async)
ret = fcntl(data->fd, F_SETOWN, getpid());
if (ret == -1) {
perror("Gnokii serial_opendevice: fcntl(F_SETOWN)");
serial_close(data);
return NULL;
goto bail;
}
#endif

Expand All @@ -202,14 +199,17 @@ void* serial_open(gn_config *cfg, int with_odd_parity, int with_async)
#endif
if (ret == -1) {
perror("Gnokii serial_opendevice: fcntl(F_SETFL)");
serial_close(data);
return NULL;
goto bail;
}
}
data->write_usleep = cfg->serial_write_usleep;
data->require_dcd = cfg->require_dcd;

return data;
bail:
serial_close(data);
free(data);
return NULL;
}


Expand All @@ -224,6 +224,11 @@ void serial_close(void *instance)
close(THIS(fd));
}

int serial_getfd(void *instance)
{
return THIS(fd);
}

/* Set the DTR and RTS bit of the serial device. */
void serial_setdtrrts(void *instance, int dtr, int rts)
{
Expand Down
5 changes: 5 additions & 0 deletions common/devices/winbluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ void bluetooth_close(void *instance)
WSACleanup();
}

int bluetooth_getfd(void *instance)
{
return (int)*(SOCKET *)instance;
}

size_t bluetooth_write(void *instance, const __ptr_t bytes, size_t size)
{
return send(*(SOCKET *)instance, bytes, size, 0);
Expand Down
28 changes: 17 additions & 11 deletions common/devices/winirda.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ void* irda_open(gn_config *cfg, int with_odd_parity, int with_async)
if ((fd = socket(AF_IRDA, SOCK_STREAM, 0)) < 0) {
perror("socket");
dprintf("Failed to create an irda socket.\n");
return NULL;
goto bail_wsa;
}
/* Discover devices */
daddr = irda_discover_device(cfg->irda_string, fd); /* discover the devices */
if (daddr == INVALID_DADDR) {
dprintf("Failed to discover any irda device.\n");
closesocket(fd);
return NULL;
goto bail_socket;
}
/* Prepare socket structure for irda socket */
peer.irdaAddressFamily = AF_IRDA;
Expand All @@ -116,26 +115,28 @@ void* irda_open(gn_config *cfg, int with_odd_parity, int with_async)
if (setsockopt(fd, SOL_IRLMP, IRLMP_9WIRE_MODE, (char *)&x, sizeof(x)) == SOCKET_ERROR) {
perror("setsockopt");
dprintf("Failed to set irda socket options.\n");
closesocket(fd);
return NULL;
goto bail_socket;
}
} else
snprintf(peer.irdaServiceName, sizeof(peer.irdaServiceName), "Nokia:PhoNet");
/* Connect to the irda socket */
if (connect(fd, (struct sockaddr *)&peer, sizeof(peer))) { /* Connect to service "Nokia:PhoNet" */
perror("connect");
dprintf("Failed to connect to irda socket\n");
closesocket(fd);
return NULL;
goto bail_socket;
}
data = malloc(sizeof(SOCKET));
if (data == NULL) {
closesocket(fd);
return NULL;
}
if (data == NULL)
goto bail_socket;
*data = fd;

return data;

bail_socket:
closesocket(fd);
bail_wsa:
WSACleanup();
return NULL;
}

void irda_close(void *instance)
Expand All @@ -145,6 +146,11 @@ void irda_close(void *instance)
WSACleanup();
}

int irda_getfd(void *instance)
{
return (int)*(SOCKET *)instance;
}

size_t irda_write(void *instance, const __ptr_t bytes, size_t size)
{
return send(*(SOCKET *)instance, bytes, size, 0);
Expand Down
Loading
Loading