Add rule for 'All devices apps' when access rule is empty.
[platform/core/connectivity/smartcard-service.git] / common / EFDIR.cpp
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18
19 #include "Debug.h"
20 #include "EFDIR.h"
21 #include "APDUHelper.h"
22 #include "SimpleTLV.h"
23
24 namespace smartcard_service_api
25 {
26         static unsigned char path_efdir[] = { 0x2f, 0x00 };
27         static ByteArray PATH_EFDIR(ARRAY_AND_SIZE(path_efdir));
28
29         EFDIR::EFDIR(Channel *channel) : FileObject(channel)
30         {
31         }
32
33         EFDIR::EFDIR(Channel *channel, const ByteArray &selectResponse) :
34                 FileObject(channel, selectResponse)
35         {
36         }
37
38         EFDIR::~EFDIR()
39         {
40         }
41
42         int EFDIR::select()
43         {
44                 int ret;
45
46                 ret = FileObject::select(PATH_EFDIR, false);
47                 if (ret < SCARD_ERROR_OK)
48                 {
49                         _ERR("EFDIR select failed, [%d]", ret);
50                 }
51
52                 return ret;
53         }
54
55         const ByteArray EFDIR::parseRecord(const Record &record, const ByteArray &aid)
56         {
57                 bool matched = false;
58                 ByteArray result;
59                 SimpleTLV tlv(record.getData());
60
61                 if (tlv.decodeTLV() == true && tlv.getTag() == 0x61)
62                 {
63                         tlv.enterToValueTLV();
64                         while (tlv.decodeTLV() == true)
65                         {
66                                 switch (tlv.getTag())
67                                 {
68                                 case 0x4F : /* aid */
69                                         if (tlv.getValue() == aid)
70                                                 matched = true;
71                                         break;
72                                 case 0x50 : /* label */
73                                         break;
74                                 case 0x51 : /* path */
75                                         result = tlv.getValue();
76                                         break;
77                                 case 0x53 : /* ddo */
78                                         break;
79                                 }
80                         }
81                         tlv.returnToParentTLV();
82
83                         if (matched == true)
84                         {
85                                 _DBG("Found!! : path %s", result.toString().c_str());
86                         }
87                         else
88                         {
89                                 result.clear();
90                         }
91                 }
92
93                 return result;
94         }
95
96         const ByteArray EFDIR::getPathByAID(const ByteArray &aid)
97         {
98                 ByteArray result;
99                 Record record;
100                 unsigned int id;
101                 int status = 0;
102
103                 for (id = 1; status >= 0; id++)
104                 {
105                         status = readRecord(0, id, record);
106                         if (status >= 0)
107                         {
108                                 result = parseRecord(record, aid);
109                                 if (result.size() > 0)
110                                         break;
111                         }
112                 }
113
114                 return result;
115         }
116 } /* namespace smartcard_service_api */