Browse Source

port supl library package

Also enhance the client to allow binding to an interface.
Phil Sutter 9 years ago
parent
commit
1f9113fee2

+ 33 - 0
package/supl/Makefile

@@ -0,0 +1,33 @@
+# This file is part of the OpenADK project. OpenADK is copyrighted
+# material, please see the LICENCE file in the top-level directory.
+
+include $(ADK_TOPDIR)/rules.mk
+
+PKG_NAME:=		supl
+PKG_VERSION:=		1.0.6
+PKG_RELEASE:=		1
+PKG_HASH:=		068dc47ce818ce5634f09a88159df85a6ce3456e2467b11b8c5f8543a99bb347
+PKG_DESCR:=		tools for accessing SUP/RRLP server
+PKG_SECTION:=		net/misc
+PKG_BUILDDEP:=		openssl
+PKG_DEPENDS:=		libopenssl
+PKG_URL:=		http://www.tajuma.com/supl/
+PKG_SITES:=		${MASTER_SITE_SOURCEFORGE:=supl/}
+DISTFILES:=             ${PKG_NAME}_${PKG_VERSION}.tar.gz
+WRKDIST=		${WRKDIR}/trunk
+
+include $(ADK_TOPDIR)/mk/package.mk
+
+$(eval $(call PKG_template,SUPL,$(PKG_NAME),$(PKG_VERSION)-${PKG_RELEASE},${PKG_DEPENDS},${PKG_DESCR},${PKG_SECTION}))
+
+CONFIG_STYLE:=		minimal
+CONFIGURE_ARGS+=	--precompiled-asn1=yes --prefix="${WRKINST}/usr"
+
+post-install:
+	$(INSTALL_DIR) $(IDIR_SUPL)/usr/{bin,lib}
+	$(INSTALL_BIN) $(WRKINST)/usr/bin/supl-{cert,client,proxy} \
+		$(IDIR_SUPL)/usr/bin
+	${CP} ${WRKINST}/usr/lib/lib{asnrrlp,asnsupl,supl}.so* \
+		${IDIR_SUPL}/usr/lib
+
+include ${ADK_TOPDIR}/mk/pkg-bottom.mk

+ 16 - 0
package/supl/patches/patch-src_Makefile

@@ -0,0 +1,16 @@
+	- use pkg-config everywhere, otherwise libs are not found
+--- trunk.orig/src/Makefile	2011-10-17 20:09:22.000000000 +0200
++++ trunk/src/Makefile	2015-02-09 16:48:37.244935714 +0100
+@@ -21,10 +21,10 @@ DIST = Makefile $(PROGRAM_SOURCE) $(SUPL
+ all: supl-client supl-proxy supl-cert
+ 
+ supl-client: libsupl.so supl-client.o
+-	$(CC) -o $@ supl-client.o -L. -lsupl -lssl -lm
++	$(CC) -o $@ supl-client.o -L. -lsupl $(shell pkg-config --libs openssl) -lm
+ 
+ supl-proxy: libsupl.so supl-proxy.o
+-	$(CC) -o $@ supl-proxy.o -L. -lsupl -lssl -lm
++	$(CC) -o $@ supl-proxy.o -L. -lsupl $(shell pkg-config --libs openssl) -lm
+ 
+ supl-cert: supl-cert.o
+ 	$(CC) -o $@ supl-cert.o $(shell pkg-config --libs openssl) -lm

+ 40 - 0
package/supl/patches/patch-src_supl-client_c

@@ -0,0 +1,40 @@
+	- implement bind to device functionality
+--- trunk.orig/src/supl-client.c	2011-10-21 20:51:38.000000000 +0200
++++ trunk/src/supl-client.c	2013-04-24 18:55:01.937252375 +0200
+@@ -252,6 +252,7 @@ static char *usage_str =
+ "  --cell gsm:mcc,mns:lac,ci|wcdma:mcc,msn,uc	set current gsm/wcdma cell id\n"
+ "  --cell gsm:mcc,mns:lac,ci:lat,lon,uncert	set known gsm cell id with position\n"
+ "  --format|-f human				machine parseable output\n"
++"  --interface|-i iface                         bind to this interface\n"
+ "  --debug|-d <n>				1 == RRLP, 2 == SUPL, 4 == DEBUG\n"
+ "  --debug-file file				write debug to file\n"
+ "  --help|-h					show this help\n"
+@@ -267,6 +268,7 @@ static struct option long_opts[] = {
+   { "cell", 1, 0, 0 },
+   { "debug", 1, 0, 'd' },
+   { "format", 1, 0, 'f' },
++  { "interface", 1, 0, 0},
+   { "test", 1, 0, 't' },
+   { "set-pos", 1, 0, 0 },
+   { "pos-helper", 1, 0, 0 },
+@@ -310,7 +312,7 @@ int main(int argc, char *argv[]) {
+     int opt_index;
+     int c;
+ 
+-    c = getopt_long(argc, argv, "ad:f:t:", long_opts, &opt_index);
++    c = getopt_long(argc, argv, "ad:f:i:t:", long_opts, &opt_index);
+     if (c == -1) break;
+     switch (c) {
+     case 0:
+@@ -374,6 +376,11 @@ int main(int argc, char *argv[]) {
+       }
+       break;
+ 
++    case 'i':
++      strncpy(ctx.iface, optarg, IFNAMSIZ);
++      ctx.iface[IFNAMSIZ] = 0;
++      break;
++
+     case 'd': 
+       {
+ 	int debug = atoi(optarg);

+ 46 - 0
package/supl/patches/patch-src_supl_c

@@ -0,0 +1,46 @@
+	- implement bind to device functionality
+--- trunk.orig/src/supl.c	2011-10-27 20:41:19.000000000 +0200
++++ trunk/src/supl.c	2013-04-24 18:56:17.742529773 +0200
+@@ -41,7 +41,7 @@ static struct supl_debug_s {
+ } debug;
+ #endif
+ 
+-static int server_connect(char *server);
++static int server_connect(char *server, char *iface);
+ static int pdu_make_ulp_start(supl_ctx_t *ctx, supl_ulp_t *pdu);
+ static int pdu_make_ulp_pos_init(supl_ctx_t *ctx, supl_ulp_t *pdu);
+ static int pdu_make_ulp_rrlp_ack(supl_ctx_t *ctx, supl_ulp_t *pdu, PDU_t *rrlp);
+@@ -236,7 +236,7 @@ int EXPORT supl_server_connect(supl_ctx_
+   if (!ctx->ssl) return E_SUPL_CONNECT;
+ 
+   if (server) {
+-    ctx->fd = server_connect(server);
++    ctx->fd = server_connect(server, ctx->iface);
+     if (ctx->fd == -1) return E_SUPL_CONNECT;
+   }
+ 
+@@ -266,7 +266,7 @@ void EXPORT supl_close(supl_ctx_t *ctx)
+ }
+ 
+ 
+-static int server_connect(char *server) {
++static int server_connect(char *server, char *iface) {
+   int fd = -1;
+   struct addrinfo *ailist, *aip;
+   struct addrinfo hint;
+@@ -283,6 +283,15 @@ static int server_connect(char *server)
+     if ((fd = socket(aip->ai_family, SOCK_STREAM, 0)) < 0) {
+       err = errno;
+     }
++
++    if (strlen(iface)) {
++      struct ifreq ifr;
++      strncpy(ifr.ifr_name, iface, IFNAMSIZ);
++      ifr.ifr_name[IFNAMSIZ - 1] = 0;
++      if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)))
++	      fprintf(stderr, "Error: binding to device %s failed\n", iface);
++    }
++
+     if (connect(fd, aip->ai_addr, aip->ai_addrlen) != 0) {
+       return -1;
+     }

+ 19 - 0
package/supl/patches/patch-src_supl_h

@@ -0,0 +1,19 @@
+	- implement bind to device functionality
+--- trunk.orig/src/supl.h	2011-10-21 20:08:29.000000000 +0200
++++ trunk/src/supl.h	2013-04-24 18:52:14.916232733 +0200
+@@ -19,6 +19,7 @@
+ #include <openssl/ssl.h>
+ #include <PDU.h>
+ #include <ULP-PDU.h>
++#include <net/if.h>
+ 
+ #define SUPL_PORT "7275"
+ 
+@@ -204,6 +205,7 @@ typedef struct supl_ctx_s {
+     size_t size;
+   } slp_session_id;
+ 
++  char iface[IFNAMSIZ + 1];
+ } supl_ctx_t;
+ 
+ int supl_ctx_new(supl_ctx_t *ctx);