From patchwork Sun Jan 15 20:32:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Baatz X-Patchwork-Id: 136206 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 87471B6F62 for ; Mon, 16 Jan 2012 07:33:20 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id EBCFF9C2E5; Sun, 15 Jan 2012 15:33:15 -0500 (EST) X-Quarantine-ID: X-Virus-Scanned: amavisd-new at maxx.shmoo.com X-Amavis-Alert: BAD HEADER, Duplicate header field: "In-Reply-To" Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id It7+XIcZrhTh; Sun, 15 Jan 2012 15:33:15 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 6A97717C029; Sun, 15 Jan 2012 15:33:01 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 30E3B9C1B1 for ; Sun, 15 Jan 2012 15:32:59 -0500 (EST) X-Quarantine-ID: X-Virus-Scanned: amavisd-new at maxx.shmoo.com X-Amavis-Alert: BAD HEADER, Duplicate header field: "In-Reply-To" Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ic9T9r6eLn2X for ; Sun, 15 Jan 2012 15:32:55 -0500 (EST) Received: from mail-ey0-f172.google.com (mail-ey0-f172.google.com [209.85.215.172]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 57B569C1B4 for ; Sun, 15 Jan 2012 15:32:55 -0500 (EST) Received: by eaai13 with SMTP id i13so185787eaa.17 for ; Sun, 15 Jan 2012 12:32:54 -0800 (PST) Received: by 10.213.17.131 with SMTP id s3mr2065715eba.141.1326659574391; Sun, 15 Jan 2012 12:32:54 -0800 (PST) Received: from gandalf.schnuecks.de (p5DE8F246.dip.t-dialin.net. [93.232.242.70]) by mx.google.com with ESMTPS id t59sm62951795eeh.10.2012.01.15.12.32.51 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 15 Jan 2012 12:32:52 -0800 (PST) Received: by gandalf.schnuecks.de (Postfix, from userid 500) id 76994402BD; Sun, 15 Jan 2012 21:32:49 +0100 (CET) From: Simon Baatz To: hostap@lists.shmoo.com Subject: [PATCH 3/4] SIM/USIM: Add function to get the MNC length from the SIM/USIM Date: Sun, 15 Jan 2012 21:32:47 +0100 Message-Id: <59615bfbda0d1a899675ac86b8018412736186a6.1326658542.git.gmbnomis@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: <20120109044329.GA16253@w1.fi> In-Reply-To: References: X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com The EF-AD (administrative data) file may contain information about the length of the MNC (2 or 3 digits) in the IMSI. This can be used to construct the realm according to 3GPP TS 23.003 during EAP-SIM or EAP-AKA authentication. Signed-hostap: Simon Baatz --- src/utils/pcsc_funcs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ src/utils/pcsc_funcs.h | 2 + 2 files changed, 54 insertions(+), 0 deletions(-) diff --git a/src/utils/pcsc_funcs.c b/src/utils/pcsc_funcs.c index c36193e..9c9f145 100644 --- a/src/utils/pcsc_funcs.c +++ b/src/utils/pcsc_funcs.c @@ -1024,6 +1024,58 @@ int scard_get_imsi(struct scard_data *scard, char *imsi, size_t *len) /** + * scard_get_mnc_len - Read length of MNC in the IMSI from SIM/USIM + * card + * @scard: Pointer to private data from scard_init() + * Returns: length (>0) on success, -1 if administrative data file cannot be + * selected, -2 if administrative data file selection returns invalid result + * code, -3 if parsing FSP template file fails (USIM only), -4 if length of + * the file is unexpected, -5 if reading file fails, -6 if MNC length is not + * in range (i.e. 2 or 3). + * + */ +int scard_get_mnc_len(struct scard_data *scard) +{ + unsigned char buf[100]; + size_t blen; + int file_size; + + wpa_printf(MSG_DEBUG, "SCARD: reading MNC len from (GSM) EF-AD"); + blen = sizeof(buf); + if (scard_select_file(scard, SCARD_FILE_GSM_EF_AD, buf, &blen)) + return -1; + if (blen < 4) { + wpa_printf(MSG_WARNING, "SCARD: too short (GSM) EF-AD " + "header (len=%ld)", (long) blen); + return -2; + } + + if (scard->sim_type == SCARD_GSM_SIM) { + file_size = (buf[2] << 8) | buf[3]; + } else { + if (scard_parse_fsp_templ(buf, blen, NULL, &file_size)) + return -3; + } + if (file_size < 4 || file_size > sizeof(buf)) { + wpa_printf(MSG_DEBUG, "SCARD: invalid file length=%ld", + (long) file_size); + return -4; + } + + if (scard_read_file(scard, buf, file_size)) + return -5; + buf[3] = buf[3] & 0x0f; /* upper nibble reserved for future use */ + if (buf[3] < 2 || buf[3] > 3) { + wpa_printf(MSG_DEBUG, "SCARD: invalid MNC length=%ld", + (long) buf[3]); + return -6; + } + wpa_printf(MSG_DEBUG, "SCARD: MNC length=%ld", (long) buf[3]); + return buf[3]; +} + + +/** * scard_gsm_auth - Run GSM authentication command on SIM card * @scard: Pointer to private data from scard_init() * @_rand: 16-byte RAND value from HLR/AuC diff --git a/src/utils/pcsc_funcs.h b/src/utils/pcsc_funcs.h index 543f7c5..483247b 100644 --- a/src/utils/pcsc_funcs.h +++ b/src/utils/pcsc_funcs.h @@ -26,6 +26,7 @@ #define SCARD_FILE_GSM_DF 0x7F20 #define SCARD_FILE_UMTS_DF 0x7F50 #define SCARD_FILE_GSM_EF_IMSI 0x6F07 +#define SCARD_FILE_GSM_EF_AD 0x6FAD #define SCARD_FILE_EF_DIR 0x2F00 #define SCARD_FILE_EF_ICCID 0x2FE2 #define SCARD_FILE_EF_CK 0x6FE1 @@ -47,6 +48,7 @@ void scard_deinit(struct scard_data *scard); int scard_set_pin(struct scard_data *scard, const char *pin); int scard_get_imsi(struct scard_data *scard, char *imsi, size_t *len); +int scard_get_mnc_len(struct scard_data *scard); int scard_gsm_auth(struct scard_data *scard, const unsigned char *_rand, unsigned char *sres, unsigned char *kc); int scard_umts_auth(struct scard_data *scard, const unsigned char *_rand,