1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-23 00:43:28 +00:00

Add libpasori 02, feliCa read/write library for Sony RC-S320

USB FeliCa R/W(PaSoRi).

PR:		ports/108173
Submitted by:	Yoshihiko Sarumaru <mistral at imasy.or.jp>
Reviewed by:	matusita
This commit is contained in:
Norikatsu Shigemura 2007-01-21 13:39:26 +00:00
parent 81a5022f95
commit a9905cdafd
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=182905
16 changed files with 410 additions and 0 deletions

View File

@ -574,6 +574,7 @@
SUBDIR += libopendaap
SUBDIR += libopensync
SUBDIR += libowfat
SUBDIR += libpasori
SUBDIR += libpci
SUBDIR += libpdel
SUBDIR += libpeak

30
devel/libpasori/Makefile Normal file
View File

@ -0,0 +1,30 @@
# New ports collection makefile for: libpasori
# Date created: 18 January 2007
# Whom: Yoshihiko Sarumaru <mistral@imasy.or.jp>
#
# $FreeBSD$
PORTNAME= libpasori
PORTVERSION= 02
CATEGORIES= devel
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE_JP}
MASTER_SITE_SUBDIR= ${PORTNAME}/20457
DISTNAME= ${PORTNAME}${PORTVERSION}
MAINTAINER= mistral@imasy.or.jp
COMMENT= FeliCa read/write library for Sony RC-S320 USB FeliCa R/W(PaSoRi)
USE_BZIP2= yes
WRKSRC= ${WRKDIR}/${PORTNAME}
post-extract:
@${MKDIR} ${WRKSRC}/lib ${WRKSRC}/lpdump ${WRKSRC}/lptest
@${CP} ${FILESDIR}/Makefile ${WRKSRC}/Makefile
@${CP} ${FILESDIR}/Makefile.lib ${WRKSRC}/lib/Makefile
@${CP} ${FILESDIR}/Makefile.lpdump ${WRKSRC}/lptest/Makefile
@${CP} ${FILESDIR}/Makefile.lptest ${WRKSRC}/lpdump/Makefile
post-install:
@${CAT} ${PKGMESSAGE}
.include <bsd.port.mk>

3
devel/libpasori/distinfo Normal file
View File

@ -0,0 +1,3 @@
MD5 (libpasori02.tar.bz2) = c23f2a3ae3d699bcd7a269dbd64120fb
SHA256 (libpasori02.tar.bz2) = 753dedbb8deb1f30d6d227f6e352714b5045badc6c86e77c651497e0b2a9bb15
SIZE (libpasori02.tar.bz2) = 6352

View File

@ -0,0 +1,5 @@
# $FreeBSD$
SUBDIR= lib lpdump lptest
.include <bsd.subdir.mk>

View File

@ -0,0 +1,18 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../src
LIB= pasori
SRCS= libpasori_command.c libpasori_com_bsdugen.c \
libpasori_polling.c
INCS= libpasori.h libpasori_com.h libpasori_command.h \
libpasori_config.h libpasori_liblocal.h
LIBDIR= ${LOCALBASE}/lib
INCLUDEDIR= ${LOCALBASE}/include
NO_PROFILE=
CFLAGS+= -D__LIBPASORI_WITH_BSDUGEN
CFLAGS+= -Wall -W
.include <bsd.lib.mk>

View File

@ -0,0 +1,14 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../src
PROG= lpdump
DPADD= libpasori.a
LDADD= -L../lib -lpasori
BINDIR= ${LOCALBASE}/bin
NO_MAN=
CFLAGS+= -Wall -W
.include <bsd.prog.mk>

View File

@ -0,0 +1,14 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../src
PROG= lptest
DPADD= libpasori.a
LDADD= -L../lib -lpasori
BINDIR= ${LOCALBASE}/bin
NO_MAN=
CFLAGS+= -Wall -W
.include <bsd.prog.mk>

View File

@ -0,0 +1,147 @@
--- src/libpasori_com_bsdugen.c.orig Mon Mar 20 09:12:58 2006
+++ src/libpasori_com_bsdugen.c Sat Jan 20 23:13:12 2007
@@ -6,7 +6,16 @@
#include <sys/ioctl.h>
#include <errno.h>
+#include <sys/param.h>
+#include <string.h>
+#include <unistd.h>
+#include <err.h>
+
#include "libpasori_liblocal.h"
+#include "libpasori.h"
+
+#define VENDOR_SONY 0x054c
+#define PRODUCT_RC_S320 0x01bb
void dbg_dump(uint8* d,int size){
int i;
@@ -16,25 +25,86 @@
Log("\n");
}
-pasori* pasori_open(char* c){ /* FIXME:unused arg. */
+void search_pasori(char* devname, int devnamelen){
+ int pathnum;
+ char buspath[16];
+ int busfd;
+
+ memset(devname, 0, devnamelen);
+ for (pathnum = 0; pathnum < 10; pathnum++) {
+ snprintf(buspath, sizeof(buspath), "/dev/usb%d", pathnum);
+ if ((busfd = open(buspath, O_RDONLY)) >= 0) {
+ int devnum;
+ for (devnum = 1; devnum < USB_MAX_DEVICES; devnum++) {
+ struct usb_device_info di;
+ di.udi_addr = devnum;
+ if (ioctl(busfd, USB_DEVICEINFO, &di) != -1) {
+ if ((di.udi_vendorNo == VENDOR_SONY) &&
+ (di.udi_productNo == PRODUCT_RC_S320)) {
+ int i;
+ for (i=0; i<USB_MAX_DEVNAMES; i++) {
+ if (strncmp(di.udi_devnames[i], "ugen", 4) == 0) {
+ snprintf(devname, devnamelen,
+ "/dev/%s", di.udi_devnames[i]);
+ devname[devnamelen -1] = '\0';
+ break;
+ }
+ }
+ }
+ }
+ if (devname[0] != '\0') break;
+ }
+ close(busfd);
+ if (devname[0] != '\0') break;
+ } else {
+ continue;
+ }
+ }
+}
+
+pasori* pasori_open(char* c){
int config;
pasori *pp;
- char* pasori_devname;
- char* pasori_intr;
+ char pasori_devname[USB_MAX_DEVNAMELEN +1];
+ char pasori_ctrl[PATH_MAX];
+ char pasori_intr[PATH_MAX];
int i;
- int t;
- const int timeout = 400;
- const int size = 0;
pp = (pasori *)malloc(sizeof(pasori));
- pasori_devname = "/dev/ugen0.00"; /* FIXME:hardcoded device path */
- pasori_intr = "/dev/ugen0.01";
-
- pp->fd_cntl = open(pasori_devname,O_RDWR);
+ if (c != NULL) {
+ snprintf(pasori_devname, sizeof(pasori_devname),
+ "%s", c);
+ pasori_devname[sizeof(pasori_devname) -1] = '\0';
+ } else {
+ search_pasori(pasori_devname, sizeof(pasori_devname));
+ if (strlen(pasori_devname) == 0) {
+ warnx("No PaSoRi was found.");
+ return NULL;
+ }
+ }
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+ snprintf(pasori_ctrl, sizeof(pasori_ctrl),
+ "%s.00", pasori_devname);
+#else
+ snprintf(pasori_ctrl, sizeof(pasori_ctrl),
+ "%s", pasori_devname);
+#endif
+ pasori_ctrl[sizeof(pasori_ctrl) -1] = '\0';
+ snprintf(pasori_intr, sizeof(pasori_intr),
+ "%s.1", pasori_devname);
+ pasori_intr[sizeof(pasori_intr) -1] = '\0';
+
+ pp->fd_cntl = open(pasori_ctrl,O_RDWR);
+ if (pp->fd_cntl == -1) {
+ warn("%s", pasori_ctrl);
+ }
config = 1;
i = ioctl(pp->fd_cntl,USB_SET_CONFIG,&config);
pp->fd_intr = open(pasori_intr,O_RDONLY | O_NONBLOCK);
+ if (pp->fd_intr == -1) {
+ warn("%s", pasori_intr);
+ }
if( (pp->fd_cntl < 0) || (pp->fd_intr < 0) ){
Log("error opening pasori.%d %d",pp->fd_cntl,pp->fd_intr);
close(pp->fd_cntl);
@@ -47,7 +117,6 @@
int pasori_send(pasori* pp,uint8 *cmd,uint8 size,int timeout){
struct usb_ctl_request req;
- uint8 msg[128]; /* FIXME:max message bytes? */
uint8 resp[256];
signed int i;
int t;
@@ -90,11 +159,12 @@
int pasori_recv(pasori* pp,uint8* buf,uint8 bufsize,int timeout){
signed int i;
int state;
- int size;
+ int size=0;
int ptr;
- int one = 1;
fd_set fds;
struct timeval tv;
+
+ (void)bufsize; /* FIXME: buffer size is not checked */
uint8 resp;
state = STATE_UNKNOWN;
@@ -156,5 +226,7 @@
void pasori_close(pasori* p){
close(p->fd_intr);
close(p->fd_cntl);
+ free(p);
+ p = NULL;
}

View File

@ -0,0 +1,44 @@
--- src/libpasori_command.c.orig Mon Mar 20 09:12:58 2006
+++ src/libpasori_command.c Fri Jan 19 01:54:43 2007
@@ -1,6 +1,7 @@
/* pasori commands */
#include "libpasori_liblocal.h"
#include <stdlib.h>
+#include <string.h>
/* FIXME: UNKNOWN CONSTANTS */
const uint8 PASORI_INIT0[] = {0x62,0x01,0x82};
@@ -24,7 +25,6 @@
void /* FIXME: return errorcode */
pasori_packet_write(pasori* p,uint8* data,int size){ /* RAW Packet SEND */
uint8 cmd[256];
- uint8 recv[256];
uint8 sum;
int i;
sum = 0;
@@ -81,6 +81,7 @@
s = recv[3];
/* FIXME:calc checksum */
/* FIXME:check buffer size */
+ (void)size;
/* FIXME:check msgid */
s--;
memcpy(data,&recv[7],s);
@@ -95,6 +96,9 @@
uint8 resp[256];
uint8 blklist[2];
int i;
+
+ (void)mode; /* FIXME: what is this argument? */
+
blklist[0] = 0;
blklist[1] = addr;
blklist[0] |= 0x80; /* element size == 2 */
@@ -124,7 +128,6 @@
/* INIT */
int
pasori_init(pasori *p){
- uint8 recv[256];
pasori_test(p,PASORI_INIT0,sizeof(PASORI_INIT0));
pasori_test(p,PASORI_INIT1,sizeof(PASORI_INIT1));
pasori_test(p,PASORI_INIT2,sizeof(PASORI_INIT2));

View File

@ -0,0 +1,13 @@
--- src/libpasori_command.h.orig Mon Mar 20 09:12:58 2006
+++ src/libpasori_command.h Fri Jan 19 00:38:48 2007
@@ -2,8 +2,8 @@
#define __LIBPASORI_COMMAND_H
int pasori_init(pasori*);
-int pasori_write(pasori*,uint8,uint8);
-int pasori_read(pasori*,uint8,uint8);
+int pasori_write(pasori*,uint8*,uint8);
+int pasori_read(pasori*,uint8*,uint8);
felica* felica_polling(pasori*,uint16,uint8,uint8);
int felica_read_without_encryption02(felica* f,int servicecode,int mode,uint8 addr,uint8* b);

View File

@ -0,0 +1,11 @@
--- src/libpasori_polling.c.orig Tue May 16 01:45:01 2006
+++ src/libpasori_polling.c Fri Jan 19 01:09:56 2007
@@ -1,6 +1,8 @@
/* libpasori polling func. */
#include <stdlib.h>
+#include <string.h>
#include "libpasori_liblocal.h"
+#include "libpasori_command.h"
felica *

View File

@ -0,0 +1,51 @@
--- src/lpdump.c.orig Tue May 16 02:55:42 2006
+++ src/lpdump.c Sat Jan 20 23:04:08 2007
@@ -1,8 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include "libpasori.h"
+#include "libpasori_command.h"
void
mydump(uint8 *p,int size){
@@ -96,7 +98,6 @@
uint16 area_end[60];
uint16 area_count;
uint16 servicecode[128];
- int servicecode_area[128];
uint16 servicecode_count;
uint16 t;
uint16 idx;
@@ -166,7 +167,7 @@
uint8 resp[256];
uint16 sc[4];
int sc_count;
- int i,j;
+ int i;
cmd[0] = 0x0c;
memcpy(&cmd[1],f->IDm,8);
@@ -188,14 +189,15 @@
}
int
-main(void){
+main(int argc, char **argv){
pasori* p;
felica* f;
- int i;
- int m;
- uint8 b[16];
- p = pasori_open(NULL);
+ char* devpath = NULL;
+ if (argc == 2) {
+ devpath = argv[1];
+ }
+ p = pasori_open(devpath);
if(!p){
printf("error\n");
exit(-1);

View File

@ -0,0 +1,44 @@
--- src/lptest.c.orig Mon Mar 20 09:12:58 2006
+++ src/lptest.c Sun Jan 21 00:36:43 2007
@@ -2,24 +2,29 @@
#include <stdlib.h>
#include "libpasori.h"
+#include "libpasori_command.h"
int
-main(void){
+main(int argc, char **argv){
pasori* p;
felica* f;
int i;
- int m;
uint8 b[16];
printf("lptest : start\n");
- p = pasori_open(NULL);
+ char* devpath = NULL;
+ if (argc == 2) {
+ devpath = argv[1];
+ }
+ p = pasori_open(devpath);
if(!p){
printf("error\n");
exit(-1);
}
pasori_init(p);
f = felica_polling(p,POLLING_ANY,0,0);
+ if (f) {
printf("read test\n");
for(i=0;i!=32;i++){
if(!felica_read_without_encryption02(f,0x090f,0,i,b)){
@@ -38,6 +43,8 @@
}
+ }
+ free(f);
}
pasori_close(p);

View File

@ -0,0 +1,4 @@
FeliCa read/write library for Sony RC-S320 USB FeliCa R/W(PaSoRi).
This library is independent from the SDK for FeliCa.
WWW: http://libpasori.sourceforge.jp/

View File

@ -0,0 +1,3 @@
******************************************************************************
Place your FeliCa card on PaSoRi before executing commands.
******************************************************************************

View File

@ -0,0 +1,8 @@
bin/lpdump
bin/lptest
include/libpasori.h
include/libpasori_command.h
include/libpasori_liblocal.h
include/libpasori_com.h
include/libpasori_config.h
lib/libpasori.a