diff -ur -x 'Makefile*' supl-0.9.1/src/supl.c supl-0.9.2/src/supl.c --- supl-0.9.1/src/supl.c 2007-10-01 18:12:20.000000000 +0300 +++ supl-0.9.2/src/supl.c 2011-03-02 18:13:22.000000000 +0200 @@ -29,6 +29,7 @@ #define PARAM_GSM_CELL_CURRENT 1 #define PARAM_GSM_CELL_KNOWN 2 +#define PARAM_WCDMA_CELL_CURRENT 4 #define OPTIONAL_MISSING ((void*)0) @@ -45,6 +46,7 @@ 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); static int supl_more_rrlp(PDU_t *rrlp); +static int supl_response_harvest(supl_ctx_t *ctx, supl_ulp_t *pdu); int supl_ulp_decode(supl_ulp_t *pdu) { ULP_PDU_t *ulp; @@ -198,7 +200,8 @@ SSL_METHOD *meth; SSLeay_add_ssl_algorithms(); - meth = TLSv1_client_method(); + // meth = TLSv1_client_method(); + meth = SSLv23_client_method(); SSL_load_error_strings(); ctx->ssl_ctx = SSL_CTX_new(meth); if (!ctx->ssl_ctx) return E_SUPL_CONNECT; @@ -221,6 +224,7 @@ FILE *fp = fopen("/tmp/s_cert.pem", "w"); if (fp) PEM_write_X509(fp, s_cert); + fclose(fp); X509_free(s_cert); } #endif @@ -276,17 +280,21 @@ ulp->version.servind = 0; session_id->sessionId = 1; - session_id->setId.present = SETId_PR_msisdn; - (void)OCTET_STRING_fromBuf(&session_id->setId.choice.msisdn, ctx->p.msisdn, 8); + // session_id->setId.present = SETId_PR_msisdn; + // (void)OCTET_STRING_fromBuf(&session_id->setId.choice.msisdn, ctx->p.msisdn, 8); + session_id->setId.present = SETId_PR_imsi; + (void)OCTET_STRING_fromBuf(&session_id->setId.choice.imsi, ctx->p.msisdn, 8); ulp->sessionID.setSessionID = session_id; ulp->sessionID.slpSessionID = OPTIONAL_MISSING; ulp->message.present = UlpMessage_PR_msSUPLSTART; ulp->message.choice.msSUPLSTART.sETCapabilities.posTechnology.agpsSETBased = 1; - (void)asn_long2INTEGER(&ulp->message.choice.msSUPLSTART.sETCapabilities.prefMethod, PrefMethod_noPreference); + // (void)asn_long2INTEGER(&ulp->message.choice.msSUPLSTART.sETCapabilities.prefMethod, PrefMethod_noPreference); + (void)asn_long2INTEGER(&ulp->message.choice.msSUPLSTART.sETCapabilities.prefMethod, PrefMethod_agpsSETBasedPreferred); ulp->message.choice.msSUPLSTART.sETCapabilities.posProtocol.rrlp = 1; + if (ctx->p.set & PARAM_GSM_CELL_CURRENT) { ulp->message.choice.msSUPLSTART.locationId.cellInfo.present = CellInfo_PR_gsmCell; ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.gsmCell.refMCC = ctx->p.gsm.mcc; ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.gsmCell.refMNC = ctx->p.gsm.mnc; @@ -294,6 +302,12 @@ ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.gsmCell.refCI = ctx->p.gsm.ci; ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.gsmCell.nMR = OPTIONAL_MISSING; ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.gsmCell.tA = OPTIONAL_MISSING; + } else if (ctx->p.set & PARAM_WCDMA_CELL_CURRENT) { + ulp->message.choice.msSUPLSTART.locationId.cellInfo.present = CellInfo_PR_wcdmaCell; + ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.wcdmaCell.refMCC = ctx->p.wcdma.mcc; + ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.wcdmaCell.refMNC = ctx->p.wcdma.mnc; + ulp->message.choice.msSUPLSTART.locationId.cellInfo.choice.wcdmaCell.refUC = ctx->p.wcdma.uc; + } (void)asn_long2INTEGER(&ulp->message.choice.msSUPLSTART.locationId.status, Status_current); @@ -310,6 +324,23 @@ return 0; } +// get slpSessionID from SUPLRESPONSE pdu if preset +static int supl_response_harvest(supl_ctx_t *ctx, supl_ulp_t *pdu) { + int ret; + ULP_PDU_t *ulp = pdu->pdu; + void *buf; + + ctx->slp_session_id.buf = 0; + + ret = uper_encode_to_new_buffer(&asn_DEF_SlpSessionID, 0, (void *)ulp->sessionID.slpSessionID, &buf); + if (ret == -1) return -1; + + ctx->slp_session_id.buf = buf; + ctx->slp_session_id.size = ret; + + return 0; +} + static int pdu_make_ulp_pos_init(supl_ctx_t *ctx, supl_ulp_t *pdu) { int err; ULP_PDU_t *ulp; @@ -326,27 +357,36 @@ ulp->version.servind = 0; session_id->sessionId = 1; - session_id->setId.present = SETId_PR_msisdn; - (void)OCTET_STRING_fromBuf(&session_id->setId.choice.msisdn, ctx->p.msisdn, 8); + // session_id->setId.present = SETId_PR_msisdn; + // (void)OCTET_STRING_fromBuf(&session_id->setId.choice.msisdn, ctx->p.msisdn, 8); + session_id->setId.present = SETId_PR_imsi; + (void)OCTET_STRING_fromBuf(&session_id->setId.choice.imsi, ctx->p.msisdn, 8); ulp->sessionID.setSessionID = session_id; + // ulp->sessionID.slpSessionID = OPTIONAL_MISSING; + if (ctx->slp_session_id.buf) { + (void)uper_decode_complete(0, &asn_DEF_SlpSessionID, (void **)&ulp->sessionID.slpSessionID, ctx->slp_session_id.buf, ctx->slp_session_id.size); + } else { ulp->sessionID.slpSessionID = OPTIONAL_MISSING; + } ulp->message.present = UlpMessage_PR_msSUPLPOSINIT; ulp->message.choice.msSUPLPOSINIT.sETCapabilities.posTechnology.agpsSETBased = 1; - (void)asn_long2INTEGER(&ulp->message.choice.msSUPLPOSINIT.sETCapabilities.prefMethod, PrefMethod_noPreference); + // (void)asn_long2INTEGER(&ulp->message.choice.msSUPLPOSINIT.sETCapabilities.prefMethod, PrefMethod_noPreference); + (void)asn_long2INTEGER(&ulp->message.choice.msSUPLPOSINIT.sETCapabilities.prefMethod, PrefMethod_agpsSETBasedPreferred); ulp->message.choice.msSUPLPOSINIT.sETCapabilities.posProtocol.rrlp = 1; - req_adata->acquisitionAssistanceRequested = 1; - req_adata->navigationModelRequested = 1; + req_adata->acquisitionAssistanceRequested = 0; // 1 + req_adata->navigationModelRequested = 0; // 1 req_adata->referenceTimeRequested = 1; - req_adata->utcModelRequested = 1; - req_adata->ionosphericModelRequested = 1; + req_adata->utcModelRequested = 0; //1 + req_adata->ionosphericModelRequested = 0; // 1 req_adata->referenceLocationRequested = 1; - req_adata->almanacRequested = 1; - req_adata->realTimeIntegrityRequested = 1; + req_adata->almanacRequested = 0; // 1 + req_adata->realTimeIntegrityRequested = 0; // 1 ulp->message.choice.msSUPLPOSINIT.requestedAssistData = req_adata; + if (ctx->p.set & PARAM_GSM_CELL_CURRENT) { ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.present = CellInfo_PR_gsmCell; ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.gsmCell.refMCC = ctx->p.gsm.mcc; ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.gsmCell.refMNC = ctx->p.gsm.mnc; @@ -354,6 +394,12 @@ ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.gsmCell.refCI = ctx->p.gsm.ci; ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.gsmCell.nMR = OPTIONAL_MISSING; ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.gsmCell.tA = OPTIONAL_MISSING; + } else if (ctx->p.set & PARAM_WCDMA_CELL_CURRENT) { + ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.present = CellInfo_PR_wcdmaCell; + ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.wcdmaCell.refMCC = ctx->p.wcdma.mcc; + ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.wcdmaCell.refMNC = ctx->p.wcdma.mnc; + ulp->message.choice.msSUPLPOSINIT.locationId.cellInfo.choice.wcdmaCell.refUC = ctx->p.wcdma.uc; + } if (ctx->p.set & PARAM_GSM_CELL_KNOWN) { Position_t *pos = calloc(1, sizeof(Position_t)); @@ -425,8 +471,10 @@ ulp->version.servind = 0; session_id->sessionId = 1; - session_id->setId.present = SETId_PR_msisdn; - (void)OCTET_STRING_fromBuf(&session_id->setId.choice.msisdn, ctx->p.msisdn, 8); + // session_id->setId.present = SETId_PR_msisdn; + // (void)OCTET_STRING_fromBuf(&session_id->setId.choice.msisdn, ctx->p.msisdn, 8); + session_id->setId.present = SETId_PR_imsi; + (void)OCTET_STRING_fromBuf(&session_id->setId.choice.imsi, ctx->p.msisdn, 8); ulp->sessionID.setSessionID = session_id; ulp->sessionID.slpSessionID = OPTIONAL_MISSING; @@ -645,6 +693,13 @@ return 0; } +int supl_ctx_free(supl_ctx_t *ctx) { + if (ctx->slp_session_id.buf) { + free(ctx->slp_session_id.buf); + ctx->slp_session_id.buf = 0; + } +} + static int supl_more_rrlp(PDU_t *rrlp) { long value; @@ -657,7 +712,8 @@ int supl_get_assist(supl_ctx_t *ctx, char *server, supl_assist_t *assist) { supl_ulp_t ulp; - memcpy(ctx->p.msisdn, "\xde\xad\xbe\xef\xf0\x0b\xaa\x42", 8); + // memcpy(ctx->p.msisdn, "\xde\xad\xbe\xef\xf0\x0b\xaa\x42", 8); + memcpy(ctx->p.msisdn, "\xFF\xFF\x91\x94\x48\x45\x83\x98", 8); /* ** connect to server @@ -689,6 +745,9 @@ return E_SUPL_SUPLRESPONSE; } + // get and copy slpSessionID if present + supl_response_harvest(ctx, &ulp); + supl_ulp_free(&ulp); /* @@ -794,6 +853,14 @@ ctx->p.known.uncert = uncert; } +void supl_set_wcdma_cell(supl_ctx_t *ctx, int mcc, int mns, int uc) { + ctx->p.set |= PARAM_WCDMA_CELL_CURRENT; + + ctx->p.wcdma.mcc = mcc; + ctx->p.wcdma.mnc = mns; + ctx->p.wcdma.uc = uc; +} + void supl_set_debug(FILE *log, int flags) { #ifdef SUPL_DEBUG debug.log = log; diff -ur -x 'Makefile*' supl-0.9.1/src/supl-client.c supl-0.9.2/src/supl-client.c --- supl-0.9.1/src/supl-client.c 2007-10-01 18:37:32.000000000 +0300 +++ supl-0.9.2/src/supl-client.c 2011-03-02 18:16:05.000000000 +0200 @@ -187,13 +187,13 @@ "Usage:\n" "%s options [supl-server]\n" "Options:\n" -" --gsm-cell mcc,mns:lac,ci set current gsm cell id\n" -" --gsm-cell mcc,mns:lac,ci:lat,lon,uncert set known gsm cell id with position\n" +" --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 human machine parseable output\n" " --debug n 1 == RRLP, 2 == SUPL, 4 == DEBUG\n" " --debug-file file write debug to file\n" "Example:\n" -"%1$s --gsm-cell=244,5:0x59e2,0x31b0:60.169995,24.939995,127 --gsm-cell=244,5:0x59e2,0x31b0\n" +"%1$s --cell=gsm:244,5:0x59e2,0x31b0:60.169995,24.939995,127 --cell=gsm:244,5:0x59e2,0x31b0\n" ; static void usage(char *progname) { @@ -201,7 +201,7 @@ } static struct option long_opts[] = { - { "gsm-cell", 1, 0, 0 }, + { "cell", 1, 0, 0 }, { "debug", 1, 0, 'd' }, { "format", 1, 0, 'f' }, { "test", 1, 0, 't' }, @@ -250,25 +250,31 @@ case 0: switch (opt_index) { - case 0: /* gsm-cell */ + case 0: /* gsm/wcdma cell */ { - int mcc, mns, lac, ci, uncertainty; + int mcc, mns, lac, ci, uc, uncertainty; double lat, lon; - if (sscanf(optarg, "%d,%d:%x,%x:%lf,%lf,%d", + if (sscanf(optarg, "gsm:%d,%d:%x,%x:%lf,%lf,%d", &mcc, &mns, &lac, &ci, &lat, &lon, &uncertainty) == 7) { supl_set_gsm_cell_known(&ctx, mcc, mns, lac, ci, lat, lon, uncertainty); break; } - if (sscanf(optarg, "%d,%d:%x,%x", + if (sscanf(optarg, "gsm:%d,%d:%x,%x", &mcc, &mns, &lac, &ci) == 4) { supl_set_gsm_cell(&ctx, mcc, mns, lac, ci); break; } + + if (sscanf(optarg, "wcdma:%d,%d,%x", + &mcc, &mns, &uc) == 3) { + supl_set_wcdma_cell(&ctx, mcc, mns, uc); + break; + } } - fprintf(stderr, "Ugh, gsm-cell\n"); + fprintf(stderr, "Ugh, cell\n"); break; case 4: /* set-pos */ @@ -317,11 +323,17 @@ supl_set_gsm_cell(&ctx, 244, 5, 0x59e2, 0x31b0); break; case 1: - supl_set_gsm_cell_known(&ctx, 244, 5, 0x59e2, 0x31b0, 60.169995, 24.939995, 121); + // supl_set_gsm_cell_known(&ctx, 244, 5, 0x59e2, 0x31b0, 60.169995, 24.939995, 121); + supl_set_gsm_cell_known(&ctx, 244, 5, 995763, 0, 60.169995, 24.939995, 121); break; case 2: - supl_set_gsm_cell(&ctx, 244, 5, 0x59e2, 0x31b0); - supl_set_gsm_cell_known(&ctx, 244, 5, 0x59e2, 0x31b0, 60.169995, 24.939995, 121); + // supl_set_gsm_cell(&ctx, 244, 5, 0x59e2, 0x31b0); + // supl_set_gsm_cell_known(&ctx, 244, 5, 0x59e2, 0x31b0, 60.169995, 24.939995, 121); + supl_set_gsm_cell(&ctx, 244, 5, 995763, 0x31b0); + supl_set_gsm_cell_known(&ctx, 244, 5, 995763, 0x31b0, 60.169995, 24.939995, 121); + break; + case 3: + supl_set_wcdma_cell(&ctx, 244, 5, 995763); break; } break; @@ -365,5 +377,7 @@ break; } + supl_ctx_free(&ctx); + return 0; } diff -ur -x 'Makefile*' supl-0.9.1/src/supl.h supl-0.9.2/src/supl.h --- supl-0.9.1/src/supl.h 2007-10-01 18:52:01.000000000 +0300 +++ supl-0.9.2/src/supl.h 2011-03-02 18:11:51.000000000 +0200 @@ -170,6 +170,10 @@ } gsm; struct { + int mcc, mnc, uc; + } wcdma; + + struct { int mcc, mnc, lac, ci; double lat, lon; int uncert; @@ -185,11 +189,18 @@ SSL *ssl; SSL_CTX *ssl_ctx; + struct { + void *buf; + size_t size; + } slp_session_id; + } supl_ctx_t; int supl_ctx_new(supl_ctx_t *ctx); +int supl_ctx_free(supl_ctx_t *ctx); void supl_set_gsm_cell(supl_ctx_t *ctx, int mcc, int mns, int lac, int ci); +void supl_set_wcdma_cell(supl_ctx_t *ctx, int mcc, int mns, int uc); void supl_set_gsm_cell_known(supl_ctx_t *ctx, int mcc, int mns, int lac, int ci, double lat, double lon, int uncert); void supl_set_server(supl_ctx_t *ctx, char *server); void supl_set_fd(supl_ctx_t *ctx, int fd); diff -ur -x 'Makefile*' supl-0.9.1/src/supl-proxy.c supl-0.9.2/src/supl-proxy.c --- supl-0.9.1/src/supl-proxy.c 2007-09-30 15:45:25.000000000 +0300 +++ supl-0.9.2/src/supl-proxy.c 2011-03-02 18:15:17.000000000 +0200 @@ -44,7 +44,8 @@ SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); - meth = TLSv1_server_method(); + // meth = TLSv1_server_method(); + meth = SSLv23_server_method(); ctx = SSL_CTX_new (meth); if (!ctx) { return 0; @@ -94,10 +95,9 @@ /* TCP connection is ready. Do server side SSL. */ ssl = SSL_new(ctx); - if (!ssl) return 0; SSL_set_fd(ssl, sd); err = SSL_accept(ssl); - if (!err) return 0; + if (err != 1) return 0; printf ("SSL connection using %s\n", SSL_get_cipher (ssl)); @@ -141,13 +141,15 @@ exit(1); } + supl_set_debug(stderr, SUPL_DEBUG_DEBUG | SUPL_DEBUG_SUPL); + supl_ctx_new(&server_ctx); supl_ctx_new(&client_ctx); /* get a client */ if (!ssl_accept(7275, &client_ctx)) { - return -40; + return 42; } /* connect to the server */ @@ -209,5 +211,8 @@ supl_close(&server_ctx); supl_close(&client_ctx); + supl_ctx_free(&server_ctx); + supl_ctx_free(&client_ctx); + return 0; } diff -ur -x 'Makefile*' supl-0.9.1/debian/changelog supl-0.9.2/debian/changelog --- supl-0.9.1/debian/changelog 2007-10-01 22:02:58.000000000 +0300 +++ supl-0.9.2/debian/changelog 2011-03-02 17:06:54.000000000 +0200 @@ -1,3 +1,11 @@ +supl (0.9.2) unstable; urgency=low + + * Uses slpSessionID if given by the supl server + * Uses wcdma and gsm cell info + * Fxied few bugs all round + + -- Tatu Mannisto Wed, 2 Mar 2011 16:02:00 -0400 + supl (0.9.1) unstable; urgency=low * Added almanac and acquisition assistance support. diff -ur -x 'Makefile*' supl-0.9.1/debian/control supl-0.9.2/debian/control --- supl-0.9.1/debian/control 2007-09-30 22:07:04.000000000 +0300 +++ supl-0.9.2/debian/control 2011-03-02 17:35:03.000000000 +0200 @@ -6,7 +6,7 @@ Standards-Version: 3.6.0 Package: supl -Architecture: armel i386 +Architecture: armel i386 amd64 Depends: ${shlibs:Depends} Suggests: Description: A-GPS SUPL (Secure User Plane) client