2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SERVERRESOURCE_H_
18 #define SERVERRESOURCE_H_
20 /* standard library header */
25 #endif /* __cplusplus */
27 /* SLP library header */
33 #include "ServerIPC.h"
34 #include "ServerDispatcher.h"
35 #include "ServerReader.h"
36 #include "ServerSession.h"
37 #include "ClientInstance.h"
38 #include "ServiceInstance.h"
39 #endif /* __cplusplus */
44 namespace smartcard_service_api
49 static unsigned int newHandle;
50 static set<unsigned int> setHandles;
51 static PMutex mutexLock;
54 static const unsigned int INVALID_HANDLE = (unsigned int)-1;
56 static unsigned int assignHandle();
57 static void releaseHandle(unsigned int);
63 /* non-static member */
64 vector<void *> libraries;
65 map<unsigned int, Terminal *> mapTerminals; /* terminal unique id <-> terminal instance map */
66 map<unsigned int, unsigned int> mapReaders; /* reader unique id <-> terminal unique id map */
67 map<int, ClientInstance *> mapClients; /* client pid <-> client instance map */
68 map<Terminal *, AccessControlList *> mapACL; /* terminal instance <-> access control instance map */
71 ServerDispatcher *serverDispatcher;
76 Terminal *createInstance(void *library);
77 bool appendSELibrary(char *library);
78 void clearSELibraries();
80 static void terminalCallback(void *terminal, int event, int error, void *user_param);
82 int _openLogicalChannel(Terminal *terminal);
83 int _closeLogicalChannel(Terminal *terminal, int channelNum);
84 bool _isAuthorizedAccess(ServerChannel *channel, int pid, ByteArray aid, vector<ByteArray> &hashes);
85 unsigned int _createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, ByteArray aid);
88 static ServerResource &getInstance();
90 /* non-static member */
91 inline void setMainLoopInstance(void *mainLoop)
93 this->mainLoop = mainLoop;
95 inline void *getMainLoopInstance()
97 return this->mainLoop;
100 int loadSecureElements();
101 void unloadSecureElements();
103 Terminal *getTerminal(unsigned int terminalID);
104 Terminal *getTerminal(const char *name);
105 Terminal *getTerminalByReaderID(unsigned int readerID);
106 unsigned int getTerminalID(const char *name);
107 int getReadersInformation(ByteArray &info);
108 bool isValidReaderHandle(unsigned int reader);
110 unsigned int createReader(unsigned int terminalID);
111 unsigned int getReaderID(const char *name);
112 void removeReader(unsigned int readerID);
114 bool createClient(void *ioChannel, int socket, int watchID, int state, int pid);
115 ClientInstance *getClient(int socket);
116 void setPID(int socket, int pid);
117 int getClientCount();
118 void removeClient(int socket);
119 void removeClients();
121 bool createService(int socket, unsigned int context);
122 ServiceInstance *getService(int socket, unsigned int context);
123 void removeService(int socket, unsigned int context);
124 void removeServices(int socket);
126 unsigned int createSession(int socket, unsigned int context, unsigned int readerID, vector<ByteArray> &certHashes, void *caller);
127 ServerSession *getSession(int socket, unsigned int context, unsigned int sessionID);
128 unsigned int getChannelCount(int socket, unsigned int context, unsigned int sessionID);
129 void removeSession(int socket, unsigned int context, unsigned int session);
130 bool isValidSessionHandle(int socket, unsigned int context, unsigned int sessionID);
132 unsigned int createChannel(int socket, unsigned int context, unsigned int sessionID, int channelType, ByteArray aid);
133 Channel *getChannel(int socket, unsigned int context, unsigned int channelID);
134 void removeChannel(int socket, unsigned int context, unsigned int channelID);
136 AccessControlList *getAccessControlList(Terminal *terminal);
137 AccessControlList *getAccessControlList(ServerChannel *channel);
139 bool sendMessageToAllClients(Message &msg);
141 friend void terminalCallback(void *terminal, int event, int error, void *user_param);
144 } /* namespace smartcard_service_api */
145 #endif /* __cplusplus */
151 #endif /* __cplusplus */
153 void server_resource_set_main_loop_instance(void *instance);
157 #endif /* __cplusplus */
159 #endif /* SERVERRESOURCE_H_ */