LCOV - code coverage report
Current view: top level - src - msft.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 88.9 % 18 16
Test Date: 2025-12-04 16:15:14 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 83.3 % 6 5

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * defines the entry point for the Microsoft Plug and Play emulation. Only used
       3                 :             :  * by vcard_emul_type.c
       4                 :             :  *
       5                 :             :  * Copyright 2019 Red Hat, Inc.
       6                 :             :  *
       7                 :             :  * Author: Jakub Jelen <jjelen@redhat.com>
       8                 :             :  *
       9                 :             :  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
      10                 :             :  * See the COPYING file in the top-level directory.
      11                 :             :  *
      12                 :             :  * References:
      13                 :             :  * https://docs.microsoft.com/en-us/windows-hardware/drivers/smartcard/discovery-process
      14                 :             :  */
      15                 :             : 
      16                 :             : #include <glib.h>
      17                 :             : 
      18                 :             : #include <string.h>
      19                 :             : #include <stdio.h>
      20                 :             : #include <stdbool.h>
      21                 :             : 
      22                 :             : #include "msft.h"
      23                 :             : #include "vcard.h"
      24                 :             : #include "vcard_emul.h"
      25                 :             : #include "card_7816.h"
      26                 :             : 
      27                 :             : static unsigned char msft_container_aid[] = {
      28                 :             :     0xa0, 0x00, 0x00, 0x03, 0x97, 0x43, 0x49, 0x44, 0x5F, 0x01, 0x00 };
      29                 :             : 
      30                 :             : /* Data returned for Get Data Instruction */
      31                 :             : static unsigned char msft_get_data[] = {
      32                 :             :     0x30, 0x1D, 0x02, 0x01, 0x00, 0x16, 0x04, 0x4D,
      33                 :             :     0x53, 0x46, 0x54, 0x30, 0x12, 0x04, 0x10, 0xE2,
      34                 :             :     0x80, 0xE9, 0xD2, 0x51, 0x88, 0x87, 0x4F, 0x81,
      35                 :             :     0xD6, 0x4F, 0x25, 0x4E, 0x38, 0x00, 0x1D
      36                 :             : };
      37                 :             : 
      38                 :             : 
      39                 :             : static VCardStatus
      40                 :          15 : msft_applet_container_process_apdu(VCard *card, VCardAPDU *apdu,
      41                 :             :                                    VCardResponse **response)
      42                 :             : {
      43                 :             :     VCardStatus ret = VCARD_FAIL;
      44                 :             :     unsigned int tag;
      45                 :             : 
      46         [ +  + ]:          15 :     switch (apdu->a_ins) {
      47                 :           6 :     case GP_GET_DATA:
      48                 :             :         /* Windows proprietary tag */
      49                 :           6 :         tag = (apdu->a_p1 & 0xff) << 8 | (apdu->a_p2 & 0xff);
      50         [ +  + ]:           6 :         if (tag == 0x7f68) {
      51                 :             :             /* Assuming the driver is on Windows */
      52                 :           3 :             vcard_set_compat(card, VCARD_COMPAT_WINDOWS);
      53                 :           3 :             *response = vcard_response_new(card, msft_get_data,
      54                 :             :                 sizeof(msft_get_data), apdu->a_Le, VCARD7816_STATUS_SUCCESS);
      55                 :             :             ret = VCARD_DONE;
      56                 :           3 :             break;
      57                 :             :         }
      58                 :           3 :         *response = vcard_make_response(VCARD7816_STATUS_ERROR_DATA_NOT_FOUND);
      59                 :             :         ret = VCARD_DONE;
      60                 :           3 :         break;
      61                 :             : 
      62                 :             :     default:
      63                 :             :         /* Let the ISO 7816 code to handle other APDUs */
      64                 :             :         ret = VCARD_NEXT;
      65                 :             :         break;
      66                 :             :     }
      67                 :          15 :     return ret;
      68                 :             : }
      69                 :             : 
      70                 :             : 
      71                 :             : /*
      72                 :             :  * Initialize the Microsoft Applet. This is the only public function in
      73                 :             :  * this file. All the rest are connected through function pointers.
      74                 :             :  */
      75                 :             : VCardStatus
      76                 :           6 : msft_card_init(G_GNUC_UNUSED VReader *reader, VCard *card)
      77                 :             : {
      78                 :             :     VCardApplet *applet;
      79                 :             : 
      80                 :             :     /* create MS PnP container */
      81                 :           6 :     applet = vcard_new_applet(msft_applet_container_process_apdu,
      82                 :             :                               NULL, msft_container_aid,
      83                 :             :                               sizeof(msft_container_aid));
      84         [ -  + ]:           6 :     if (applet == NULL) {
      85                 :           0 :         goto failure;
      86                 :             :     }
      87                 :           6 :     vcard_add_applet(card, applet);
      88                 :             : 
      89                 :           6 :     return VCARD_DONE;
      90                 :             : 
      91                 :             : failure:
      92                 :           0 :     return VCARD_FAIL;
      93                 :             : }
      94                 :             : 
      95                 :             : /* vim: set ts=4 sw=4 tw=0 noet expandtab: */
        

Generated by: LCOV version 2.0-1