Montes Jean-Bastien | 4 Apr 2006 17:14

IRDA DONGLE

hello,

I have a problem with irda under linux. I have a irda dongle wich must
to discuss with a irda material: (irda dongle USB : sigmatel 4200)
	irattach irda0 -s /dev/null
I have write a program which turns on the linux and that discusses with
the equipment IRDA
I open a socket then I identify the equipment with the getsockopt but
the equipment don't answer.

I send you my code.If somebody has an idea.For information, this code
function under windows 2000 with a setsockopt (mode 9-wire).
thanks.

CODE:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <linux/types.h>
#include <linux/irda.h>

#include <linux/ircomm_param.h>

#ifndef AF_IRDA /*socket.h*/
#define AF_IRDA 23
#endif

#define IAS_SET_ATTRIB_MAX_LEN 22;

#define MAX_DEVICES 10

#define DISC_BUF_LEN	sizeof(struct irda_device_list)+ sizeof(struct irda_device_info) * ( MAX_DEVICES)
#define IRLMP_9WIRE_MODE 0x04

struct irda_device_list *list;
unsigned char buf[DISC_BUF_LEN];

int search_devices(int fd)
{

int len;
int i;
int daddr = 0;
int erreur_getsockopt;
int connfd;
int self;
int pid;

list = (struct irda_device_list *) buf;
len = DISC_BUF_LEN;

if ( erreur_getsockopt = getsockopt(fd, SOL_IRLMP, IRLMP_ENUMDEVICES,(char * )list,&len))
{perror("Aucun service trouvé"); exit(-1);}

if (len > 0) {

	printf("Discovered:\n");
	for (i=0;i<list->len;i++) {
		printf("  daddr: %08x", list->dev[i].daddr);
		printf("  saddr: %08x", list->dev[i].saddr);
		printf("  name:  %s\n", list->dev[i].info);
		daddr = list->dev[i].daddr;
	}
}
else 
{
                printf("No devices discovered.\n");
}

return daddr;
}

int sendfile() {

int fd;
struct sockaddr_irda peer;
struct ircomm_tty_cb *self;
struct ircomm_params param_irda;
int daddr;
FILE* f;
unsigned char buf[4096];
unsigned char sendchar[512]="command"; //COMMAND TO SEND
int rc;
int error;
int buflen;
char * test_car;

struct irda_ias_set ias_set;
int len;
int length_buffer = 512;

fd = socket(AF_IRDA, SOCK_STREAM, 0);
if (fd < 0) {
	perror("socket");
	if (errno == EINVAL) 
		fprintf(stderr, "Impossible d'ouvrir une socket\n");
		exit(-1);
	}

daddr = search_devices(fd);
printf("  daddr en dehors: %08x\n", daddr);
	if (!daddr) {
		fprintf(stderr,"device IRDA (--> ZOLL)  not found\n");
		exit(1);
	}

strcpy(ias_set.irda_class_name, "IrDA:IrCOMM");
strcpy(ias_set.irda_attrib_name, "IrDA:TinyTP:LsapSel");
ias_set.irda_attrib_type = IAS_STRING;
ias_set.attribute.irda_attrib_string.len = 20;
ias_set.daddr=daddr;
if (setsockopt(fd, SOL_IRLMP, IRLMP_IAS_SET, (const char *) &ias_set, sizeof (ias_set) ) )
{
printf("erreur setsockopt\n");
}

printf("******************************\n");
printf("FAMILLE:  %d\n",peer.sir_family);
printf("LSAP:  %d\n",peer.sir_lsap_sel);
printf("ADDR:  %d\n",peer.sir_addr);
printf("NAME:  %s\n",peer.sir_name);
printf("******************************\n");

peer.sir_addr = daddr;
peer.sir_family = AF_IRDA;
strcpy(peer.sir_name, "IrDA:IrCOMM");

printf("******************************\n");
printf("FAMILLE:  %d\n",peer.sir_family);
printf("LSAP:  %d\n",peer.sir_lsap_sel);
printf("ADDR:  %08x\n",peer.sir_addr);
printf("NAME:  %s\n",peer.sir_name);
printf("******************************\n");

if (connect(fd, (struct sockaddr *) &peer, sizeof(struct sockaddr_irda))) 
{
	perror("connect");
	if (errno == ENETUNREACH){
		fprintf(stderr, "impossible d'établir une connexion\n");
		exit(-1);
}
}

printf ("send\n");
error = send(fd,sendchar, 6, 0);
if (error == -1){
	printf("error_send\n");
}
else
{
	printf("ok: %d %s\n", error,(const char *)sendchar);
}

printf ("recv\n");
recv( fd, buf,4096, 0); //4096
printf("---buffer:%s---\n", buf);

close(fd);
}

int main(){

sendfile();
return 0;
}

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642

Gmane