diff options
-rw-r--r-- | host/Makefile | 7 | ||||
-rw-r--r-- | host/ausb/ausb.h | 3 | ||||
-rw-r--r-- | host/ausb/usb.c | 1 | ||||
-rw-r--r-- | host/ausb/usb.h | 5 | ||||
-rw-r--r-- | host/opcd_presence.c | 107 | ||||
-rw-r--r-- | host/opcd_usb.c | 3 |
6 files changed, 122 insertions, 4 deletions
diff --git a/host/Makefile b/host/Makefile index 12edce0..8d27808 100644 --- a/host/Makefile +++ b/host/Makefile @@ -1,8 +1,8 @@ #!/usr/bin/make LDFLAGS=-lusb -lcrypt #-lzebvty -Lzebvty/ -CFLAGS=-Wall +CFLAGS=-Wall -I../firmware/include -all: opcd_test opcd_sh +all: opcd_presence opcd_test opcd_sh clean: -rm -f *.o opcd_test @@ -11,6 +11,9 @@ clean: ausb/libausb.a: $(MAKE) -C ausb libausb.a +opcd_presence: opcd_presence.o opcd_usb.o ausb/libausb.a + $(CC) $(LDFLAGS) -L/usr/lib -lcurl -lidn -lssl -lcrypto -ldl -lz -o $@ $^ + opcd_test: opcd_test.o opcd_usb.o ausb/libausb.a $(CC) $(LDFLAGS) -o $@ $^ diff --git a/host/ausb/ausb.h b/host/ausb/ausb.h index 4d62cac..96247bb 100644 --- a/host/ausb/ausb.h +++ b/host/ausb/ausb.h @@ -9,6 +9,9 @@ * Distributed under the terms of GNU LGPL, Version 2.1 */ +#ifndef __user +#define __user +#endif/*__user*/ #include <usb.h> #include <linux/usbdevice_fs.h> diff --git a/host/ausb/usb.c b/host/ausb/usb.c index 1f1078d..1d3aaf4 100644 --- a/host/ausb/usb.c +++ b/host/ausb/usb.c @@ -4,6 +4,7 @@ #include <errno.h> #include <usb.h> #include <sys/ioctl.h> +#include "usb.h" #include <linux/usbdevice_fs.h> #define MAX_READ_WRITE 4096 diff --git a/host/ausb/usb.h b/host/ausb/usb.h index 66be0ee..979d30c 100644 --- a/host/ausb/usb.h +++ b/host/ausb/usb.h @@ -1,5 +1,10 @@ #ifndef _AUSB_USB_H #define _AUSB_USB_H + +#ifndef __user +#define __user +#endif/*__user*/ + int __usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int length, int timeout); int __usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int length, diff --git a/host/opcd_presence.c b/host/opcd_presence.c new file mode 100644 index 0000000..47333df --- /dev/null +++ b/host/opcd_presence.c @@ -0,0 +1,107 @@ +/* opcd_test - Low-Level test program for OpenPCD + * (C) 2006 by Harald Welte <laforge@gnumonks.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define __user + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#define _GNU_SOURCE +#include <getopt.h> +#include <errno.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <fcntl.h> + +#include <usb.h> + +#include <openpcd.h> +#include "opcd_usb.h" + +#include <curl/curl.h> + +int main(int argc, char **argv) +{ + struct opcd_handle *od; + int retlen; + unsigned int uid; + unsigned char *data; + static unsigned char buf[8192]; + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(!curl) + { + printf("Can't open CURL library\n"); + exit(1); + } + + curl_easy_setopt(curl, CURLOPT_URL, "http://medusa.benutzerserver.de/openpcd.announce.php"); + curl_easy_setopt(curl, CURLOPT_POST, 1); + + od = NULL; + + while (1) + { + if(od) + { + retlen = opcd_send_command(od, OPENPCD_CMD_PRESENCE_UID_GET, 0, 0, 0, NULL); + if(retlen<=0) + { + opcd_fini(od); + od=NULL; + } + else + { + retlen = opcd_recv_reply(od, (char*)buf, sizeof(struct openpcd_hdr)+4); + if (retlen == (sizeof(struct openpcd_hdr)+4) ) + { + data = buf + sizeof(struct openpcd_hdr); + + uid= ((unsigned int)data[0])<<24 | + ((unsigned int)data[1])<<16 | + ((unsigned int)data[2])<< 8 | + ((unsigned int)data[3]); + + sprintf((char*)buf,"uid=%08X",uid); + printf("%s\n",buf); + + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf); + res = curl_easy_perform(curl); + if(res) + printf("CURL: error(%i)\n",res); + } + } + } + else + { + printf("STATUS: reinitializing\n"); + od = opcd_init(0); + } + // sleep for 250ms + usleep(1000*250); + } + + /* always cleanup */ + curl_easy_cleanup(curl); + + return(0); +} diff --git a/host/opcd_usb.c b/host/opcd_usb.c index d5f7db9..842a6f1 100644 --- a/host/opcd_usb.c +++ b/host/opcd_usb.c @@ -26,7 +26,7 @@ #include <sys/types.h> #include "ausb/ausb.h" -#include "../firmware/include/openpcd.h" +#include <openpcd.h> #include "opcd_usb.h" @@ -83,7 +83,6 @@ static void opcd_dump_hdr(struct openpcd_hdr *hdr) static void handle_interrupt(struct usbdevfs_urb *uurb, void *userdata) { - struct opcd_handle *od = userdata; ausb_dev_handle *ah; struct openpcd_hdr *opcdh; |