Lines Matching defs:scard
226 static int _scard_select_file(struct scard_data *scard, unsigned short file_id,
230 static int scard_select_file(struct scard_data *scard, unsigned short file_id,
232 static int scard_verify_pin(struct scard_data *scard, const char *pin);
233 static int scard_get_record_len(struct scard_data *scard,
235 static int scard_read_record(struct scard_data *scard,
253 wpa_printf(MSG_DEBUG, "SCARD: file header did not "
263 wpa_hexdump(MSG_DEBUG, "SCARD: file header FSP template",
267 wpa_printf(MSG_MSGDUMP, "SCARD: file header TLV "
279 wpa_printf(MSG_DEBUG, "SCARD: file_size=%d",
286 wpa_printf(MSG_DEBUG, "SCARD: PS_DO=0x%02x",
300 static int scard_pin_needed(struct scard_data *scard,
303 if (scard->sim_type == SCARD_GSM_SIM) {
310 if (scard->sim_type == SCARD_USIM) {
325 static int scard_get_aid(struct scard_data *scard, unsigned char *aid,
342 if (scard_select_file(scard, SCARD_FILE_EF_DIR, buf, &blen)) {
343 wpa_printf(MSG_DEBUG, "SCARD: Failed to read EF_DIR");
346 wpa_hexdump(MSG_DEBUG, "SCARD: EF_DIR select", buf, blen);
349 rlen = scard_get_record_len(scard, rec,
352 wpa_printf(MSG_DEBUG, "SCARD: Failed to get EF_DIR "
358 wpa_printf(MSG_DEBUG, "SCARD: Too long EF_DIR record");
361 if (scard_read_record(scard, buf, rlen, rec,
363 wpa_printf(MSG_DEBUG, "SCARD: Failed to read "
367 wpa_hexdump(MSG_DEBUG, "SCARD: EF_DIR record", buf, rlen);
370 wpa_printf(MSG_DEBUG, "SCARD: Unexpected application "
377 wpa_printf(MSG_DEBUG, "SCARD: Too long application "
384 wpa_printf(MSG_DEBUG, "SCARD: Unexpected application "
390 wpa_printf(MSG_DEBUG, "SCARD: Invalid AID length %d",
395 wpa_hexdump(MSG_DEBUG, "SCARD: AID from EF_DIR record",
400 wpa_printf(MSG_DEBUG, "SCARD: 3G USIM app found from "
407 wpa_printf(MSG_DEBUG, "SCARD: 3G USIM app not found "
413 wpa_printf(MSG_DEBUG, "SCARD: Too long AID");
438 struct scard_data *scard;
449 wpa_printf(MSG_DEBUG, "SCARD: initializing smart card interface");
452 scard = os_zalloc(sizeof(*scard));
453 if (scard == NULL)
457 &scard->ctx);
459 wpa_printf(MSG_DEBUG, "SCARD: Could not establish smart card "
464 ret = SCardListReaders(scard->ctx, NULL, NULL, &len);
466 wpa_printf(MSG_DEBUG, "SCARD: SCardListReaders failed "
476 wpa_printf(MSG_INFO, "SCARD: malloc failed\n");
480 ret = SCardListReaders(scard->ctx, NULL, readers, &len);
482 wpa_printf(MSG_DEBUG, "SCARD: SCardListReaders failed(2) "
487 wpa_printf(MSG_WARNING, "SCARD: No smart card readers "
496 wpa_printf(MSG_DEBUG, "SCARD: Selected reader='%S'", readers);
498 wpa_printf(MSG_DEBUG, "SCARD: Selected reader='%s'", readers);
501 ret = SCardConnect(scard->ctx, readers, SCARD_SHARE_SHARED,
502 SCARD_PROTOCOL_T0, &scard->card, &scard->protocol);
514 wpa_printf(MSG_DEBUG, "SCARD: card=0x%x active_protocol=%lu (%s)",
515 (unsigned int) scard->card, scard->protocol,
516 scard->protocol == SCARD_PROTOCOL_T0 ? "T0" : "T1");
518 ret = SCardBeginTransaction(scard->card);
520 wpa_printf(MSG_DEBUG, "SCARD: Could not begin transaction: "
528 scard->sim_type = SCARD_GSM_SIM;
530 wpa_printf(MSG_DEBUG, "SCARD: verifying USIM support");
531 if (_scard_select_file(scard, SCARD_FILE_MF, buf, &blen,
533 wpa_printf(MSG_DEBUG, "SCARD: USIM is not supported");
536 wpa_printf(MSG_DEBUG, "SCARD: Trying to use GSM SIM");
537 scard->sim_type = SCARD_GSM_SIM;
539 wpa_printf(MSG_DEBUG, "SCARD: USIM is supported");
540 scard->sim_type = SCARD_USIM;
544 if (scard->sim_type == SCARD_GSM_SIM) {
546 if (scard_select_file(scard, SCARD_FILE_MF, buf, &blen)) {
547 wpa_printf(MSG_DEBUG, "SCARD: Failed to read MF");
552 if (scard_select_file(scard, SCARD_FILE_GSM_DF, buf, &blen)) {
553 wpa_printf(MSG_DEBUG, "SCARD: Failed to read GSM DF");
560 aid_len = scard_get_aid(scard, aid, sizeof(aid));
562 wpa_printf(MSG_DEBUG, "SCARD: Failed to find AID for "
567 wpa_hexdump(MSG_DEBUG, "SCARD: 3G USIM AID", aid, aid_len);
572 if (_scard_select_file(scard, 0, buf, &blen, scard->sim_type,
574 wpa_printf(MSG_INFO, "SCARD: Failed to read 3G USIM "
576 wpa_hexdump(MSG_INFO, "SCARD: 3G USIM AID",
583 pin_needed = scard_pin_needed(scard, buf, blen);
585 wpa_printf(MSG_DEBUG, "SCARD: Failed to determine whether PIN "
590 scard->pin1_required = 1;
594 ret = SCardEndTransaction(scard->card, SCARD_LEAVE_CARD);
596 wpa_printf(MSG_DEBUG, "SCARD
600 return scard;
604 SCardEndTransaction(scard->card, SCARD_LEAVE_CARD);
606 scard_deinit(scard);
613 * @scard: Pointer to private data from scard_init()
617 int scard_set_pin(struct scard_data *scard, const char *pin)
619 if (scard == NULL)
623 if (scard->pin1_required) {
629 if (scard_verify_pin(scard, pin)) {
642 * @scard: Pointer to private data from scard_init()
646 void scard_deinit(struct scard_data *scard)
650 if (scard == NULL)
653 wpa_printf(MSG_DEBUG, "SCARD: deinitializing smart card interface");
654 if (scard->card) {
655 ret = SCardDisconnect(scard->card, SCARD_UNPOWER_CARD);
657 wpa_printf(MSG_DEBUG, "SCARD: Failed to disconnect "
662 if (scard->ctx) {
663 ret = SCardReleaseContext(scard->ctx);
669 os_free(scard);
674 static long scard_transmit(struct scard_data *scard,
681 wpa_hexdump_key(MSG_DEBUG, "SCARD: scard_transmit: send",
684 ret = SCardTransmit(scard->card,
685 scard->protocol == SCARD_PROTOCOL_T1 ?
691 wpa_hexdump(MSG_DEBUG, "SCARD: scard_transmit: recv",
694 wpa_printf(MSG_WARNING, "SCARD: SCardTransmit failed "
701 static int _scard_select_file(struct scard_data *scard, unsigned short file_id,
719 wpa_printf(MSG_DEBUG, "SCARD: select file %04x", file_id);
721 wpa_hexdump(MSG_DEBUG, "SCARD: select file by AID",
735 ret = scard_transmit(scard, cmd, cmdlen, resp, &len);
737 wpa_printf(MSG_WARNING, "SCARD: SCardTransmit failed "
743 wpa_printf(MSG_WARNING, "SCARD: unexpected resp len "
750 wpa_printf(MSG_WARNING, "SCARD: Security status not satisfied "
756 wpa_printf(MSG_DEBUG, "SCARD: used CLA not supported");
761 wpa_printf(MSG_WARNING, "SCARD: unexpected response 0x%02x "
767 wpa_printf(MSG_DEBUG, "SCARD: trying to get response (%d bytes)",
771 ret = scard_transmit(scard, get_resp, sizeof(get_resp), buf, &rlen);
777 wpa_printf(MSG_WARNING, "SCARD: SCardTransmit err=0x%lx\n", ret);
782 static int scard_select_file(struct scard_data *scard, unsigned short file_id,
785 return _scard_select_file(scard, file_id, buf, buf_len,
786 scard->sim_type, NULL, 0);
790 static int scard_get_record_len(struct scard_data *scard, unsigned char recnum,
798 if (scard->sim_type == SCARD_USIM)
805 ret = scard_transmit(scard, cmd, sizeof(cmd), buf, &blen);
807 wpa_printf(MSG_DEBUG, "SCARD: failed to determine file "
812 wpa_hexdump(MSG_DEBUG, "SCARD: file length determination response",
816 wpa_printf(MSG_DEBUG, "SCARD: unexpected response to file "
825 static int scard_read_record(struct scard_data *scard,
834 if (scard->sim_type == SCARD_USIM)
844 ret = scard_transmit(scard, cmd, sizeof(cmd), buf, &blen);
850 wpa_printf(MSG_DEBUG, "SCARD: record read returned unexpected "
858 wpa_printf(MSG_DEBUG, "SCARD: record read returned unexpected "
872 static int scard_read_file(struct scard_data *scard,
886 if (scard->sim_type == SCARD_USIM)
888 ret = scard_transmit(scard, cmd, sizeof(cmd), buf, &blen);
894 wpa_printf(MSG_DEBUG, "SCARD: file read returned unexpected "
902 wpa_printf(MSG_DEBUG, "SCARD: file read returned unexpected "
916 static int scard_verify_pin(struct scard_data *scard, const char *pin)
923 wpa_printf(MSG_DEBUG, "SCARD: verifying PIN");
928 if (scard->sim_type == SCARD_USIM)
934 ret = scard_transmit(scard, cmd, sizeof(cmd), resp, &len);
939 wpa_printf(MSG_WARNING, "SCARD: PIN verification failed");
943 wpa_printf(MSG_DEBUG, "SCARD: PIN verified successfully");
950 * @scard: Pointer to private data from scard_init()
962 int scard_get_imsi(struct scard_data *scard, char *imsi, size_t *len)
968 wpa_printf(MSG_DEBUG, "SCARD: reading IMSI from (GSM) EF-IMSI");
970 if (scard_select_file(scard, SCARD_FILE_GSM_EF_IMSI, buf, &blen))
973 wpa_printf(MSG_WARNING, "SCARD: too short (GSM) EF-IMSI "
978 if (scard->sim_type == SCARD_GSM_SIM) {
987 wpa_printf(MSG_DEBUG, "SCARD: invalid IMSI file length=%ld",
993 wpa_printf(MSG_DEBUG, "SCARD: IMSI file length=%ld imsilen=%ld",
1000 if (scard_read_file(scard, buf, blen))
1028 * @scard: Pointer to private data from scard_init()
1041 int scard_gsm_auth(struct scard_data *scard, const unsigned char *_rand,
1051 if (scard == NULL)
1054 wpa_hexdump(MSG_DEBUG, "SCARD: GSM auth - RAND", _rand, 16);
1055 if (scard->sim_type == SCARD_GSM_SIM) {
1067 ret = scard_transmit(scard, cmd, cmdlen, resp, &len);
1071 if ((scard->sim_type == SCARD_GSM_SIM &&
1073 (scard->sim_type == SCARD_USIM &&
1075 wpa_printf(MSG_WARNING, "SCARD: unexpected response for GSM "
1083 ret = scard_transmit(scard, get_resp, sizeof(get_resp), buf, &len);
1087 if (scard->sim_type == SCARD_GSM_SIM) {
1089 wpa_printf(MSG_WARNING, "SCARD: unexpected data "
1098 wpa_printf(MSG_WARNING, "SCARD: unexpected data "
1104 wpa_printf(MSG_WARNING, "SCARD: unexpected SREC/Kc "
1112 wpa_hexdump(MSG_DEBUG, "SCARD: GSM auth - SRES", sres, 4);
1113 wpa_hexdump(MSG_DEBUG, "SCARD: GSM auth - Kc", kc, 8);
1121 * @scard: Pointer to private data from scard_init()
1139 int scard_umts_auth(struct scard_data *scard, const unsigned char *_rand,
1151 if (scard == NULL)
1154 if (scard->sim_type == SCARD_GSM_SIM) {
1155 wpa_printf(MSG_ERROR, "SCARD: Non-USIM card - cannot do UMTS "
1160 wpa_hexdump(MSG_DEBUG, "SCARD: UMTS auth - RAND", _rand, AKA_RAND_LEN);
1161 wpa_hexdump(MSG_DEBUG, "SCARD: UMTS auth - AUTN", autn, AKA_AUTN_LEN);
1168 ret = scard_transmit(scard, cmd, sizeof(cmd), resp, &len);
1173 wpa_hexdump(MSG_DEBUG, "SCARD: UMTS alg response", resp, len);
1176 wpa_printf(MSG_WARNING, "SCARD: UMTS auth failed - "
1180 wpa_printf(MSG_WARNING, "SCARD: unexpected response for UMTS "
1188 ret = scard_transmit(scard, get_resp, sizeof(get_resp), buf, &len);
1192 wpa_hexdump(MSG_DEBUG, "SCARD: UMTS get response result", buf, len);
1195 wpa_printf(MSG_DEBUG, "SCARD: UMTS Synchronization-Failure");
1197 wpa_hexdump(MSG_DEBUG, "SCARD: AUTS", auts, AKA_AUTS_LEN);
1205 wpa_printf(MSG_DEBUG, "SCARD: Invalid RES");
1211 SCARD: RES", res, *res_len);
1215 wpa_printf(MSG_DEBUG, "SCARD: Invalid CK");
1221 wpa_hexdump(MSG_DEBUG, "SCARD: CK", ck, CK_LEN);
1225 wpa_printf(MSG_DEBUG, "SCARD: Invalid IK");
1231 wpa_hexdump(MSG_DEBUG, "SCARD: IK", ik, IK_LEN);
1236 wpa_printf(MSG_DEBUG, "SCARD: Unrecognized response");