- Fix the prevent problems.
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Fri, 23 Nov 2012 07:02:50 +0000 (16:02 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Fri, 23 Nov 2012 07:02:50 +0000 (16:02 +0900)
 - Enhance SE add/remove process

Change-Id: I7a69441cdd7059094be3de3507f5abf8d7c856e5

24 files changed:
client/ClientChannel.cpp
client/ClientIPC.cpp
client/Reader.cpp
client/SEService.cpp
client/Session.cpp
client/include/Reader.h
common/DispatcherHelper.cpp
common/ReaderHelper.cpp
common/SignatureHelper.cpp
common/include/Message.h
common/include/ReaderHelper.h
packaging/smartcard-service [new file with mode: 0644]
packaging/smartcard-service-common [new file with mode: 0644]
packaging/smartcard-service-server [new file with mode: 0644]
packaging/smartcard-service.spec
server/ServerResource.cpp
server/include/ServerResource.h
server/include/SmartcardDbus.h [new file with mode: 0644]
server/smartcard-service.service [new file with mode: 0644]
server/smartcard-service.xml [new file with mode: 0644]
smartcard-service-common-devel.manifest [new file with mode: 0644]
smartcard-service-devel.manifest [new file with mode: 0644]
test-client/test-client-sync.cpp [new file with mode: 0644]
test-client/test-client.cpp

index 2a035c2..0a903ac 100644 (file)
@@ -26,6 +26,7 @@
 #include "Message.h"
 #include "ClientIPC.h"
 #include "ClientChannel.h"
+#include "ReaderHelper.h"
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
@@ -59,52 +60,66 @@ namespace smartcard_service_api
 
        void ClientChannel::closeSync()
        {
-               Message msg;
-               int rv;
-
 #ifdef CLIENT_IPC_THREAD
                if (isClosed() == false)
                {
-                       /* send message to server */
-                       msg.message = Message::MSG_REQUEST_CLOSE_CHANNEL;
-                       msg.param1 = (int)handle;
-                       msg.error = (unsigned int)context; /* using error to context */
-                       msg.caller = (void *)this;
-                       msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
+                       if (getSession()->getReader()->isSecureElementPresent() == true)
+                       {
+                               Message msg;
+                               int rv;
 
-                       ClientIPC::getInstance().sendMessage(&msg);
+                               /* send message to server */
+                               msg.message = Message::MSG_REQUEST_CLOSE_CHANNEL;
+                               msg.param1 = (int)handle;
+                               msg.error = (unsigned int)context; /* using error to context */
+                               msg.caller = (void *)this;
+                               msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
-                       syncLock();
-                       rv = waitTimedCondition(0);
-                       syncUnlock();
+                               ClientIPC::getInstance().sendMessage(&msg);
+
+                               syncLock();
+                               rv = waitTimedCondition(0);
+                               syncUnlock();
+
+                               if (rv < 0)
+                               {
+                                       SCARD_DEBUG_ERR("closeSync failed [%d]", rv);
+                               }
 
-                       if (rv < 0)
+                               channelNum = -1;
+                       }
+                       else
                        {
-                               SCARD_DEBUG_ERR("closeSync failed [%d]", rv);
+                               SCARD_DEBUG_ERR("unavailable channel");
                        }
-
-                       channelNum = -1;
                }
 #endif
        }
 
        int ClientChannel::close(closeCallback callback, void *userParam)
        {
-               Message msg;
-
                if (isClosed() == false)
                {
-                       channelNum = -1;
+                       if (getSession()->getReader()->isSecureElementPresent() == true)
+                       {
+                               Message msg;
 
-                       /* send message to server */
-                       msg.message = Message::MSG_REQUEST_CLOSE_CHANNEL;
-                       msg.param1 = (int)handle;
-                       msg.error = (unsigned int)context; /* using error to context */
-                       msg.caller = (void *)this;
-                       msg.callback = (void *)callback;
-                       msg.userParam = userParam;
+                               channelNum = -1;
 
-                       ClientIPC::getInstance().sendMessage(&msg);
+                               /* send message to server */
+                               msg.message = Message::MSG_REQUEST_CLOSE_CHANNEL;
+                               msg.param1 = (int)handle;
+                               msg.error = (unsigned int)context; /* using error to context */
+                               msg.caller = (void *)this;
+                               msg.callback = (void *)callback;
+                               msg.userParam = userParam;
+
+                               ClientIPC::getInstance().sendMessage(&msg);
+                       }
+                       else
+                       {
+                               SCARD_DEBUG_ERR("unavailable channel");
+                       }
                }
 
                return 0;
@@ -112,52 +127,74 @@ namespace smartcard_service_api
 
        int ClientChannel::transmitSync(ByteArray command, ByteArray &result)
        {
-               Message msg;
-               int rv;
+               int rv = -1;
+
+               if (getSession()->getReader()->isSecureElementPresent() == true)
+               {
+                       Message msg;
 
 #ifdef CLIENT_IPC_THREAD
-               /* send message to server */
-               msg.message = Message::MSG_REQUEST_TRANSMIT;
-               msg.param1 = (int)handle;
-               msg.param2 = 0;
-               msg.data = command;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
-
-               ClientIPC::getInstance().sendMessage(&msg);
-
-               syncLock();
-               rv = waitTimedCondition(0);
-               syncUnlock();
-
-               if (rv < 0)
+                       /* send message to server */
+                       msg.message = Message::MSG_REQUEST_TRANSMIT;
+                       msg.param1 = (int)handle;
+                       msg.param2 = 0;
+                       msg.data = command;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
+
+                       ClientIPC::getInstance().sendMessage(&msg);
+
+                       syncLock();
+                       rv = waitTimedCondition(0);
+                       syncUnlock();
+
+                       if (rv >= 0)
+                       {
+                               result = response;
+
+                               rv = 0;
+                       }
+                       else
+                       {
+                               SCARD_DEBUG_ERR("clientIPC is null");
+
+                               rv = -1;
+                       }
+#endif
+               }
+               else
                {
-                       SCARD_DEBUG_ERR("clientIPC is null");
+                       SCARD_DEBUG_ERR("unavailable channel");
 
-                       return -1;
+                       rv = -1;
                }
 
-               result = response;
-#endif
-               return 0;
+               return rv;
        }
 
        int ClientChannel::transmit(ByteArray command, transmitCallback callback, void *userParam)
        {
-               Message msg;
+               if (getSession()->getReader()->isSecureElementPresent() == true)
+               {
+                       Message msg;
 
-               /* send message to server */
-               msg.message = Message::MSG_REQUEST_TRANSMIT;
-               msg.param1 = (int)handle;
-               msg.param2 = 0;
-               msg.data = command;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)callback;
-               msg.userParam = userParam;
+                       /* send message to server */
+                       msg.message = Message::MSG_REQUEST_TRANSMIT;
+                       msg.param1 = (int)handle;
+                       msg.param2 = 0;
+                       msg.data = command;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)callback;
+                       msg.userParam = userParam;
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       ClientIPC::getInstance().sendMessage(&msg);
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("unavailable channel");
+               }
 
                return 0;
        }
@@ -183,7 +220,7 @@ namespace smartcard_service_api
                                /* transmit result */
                                SCARD_DEBUG("MSG_REQUEST_TRANSMIT");
 
-                               if (msg->callback == (void *)channel) /* synchronized call */
+                               if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
                                        channel->syncLock();
@@ -209,7 +246,7 @@ namespace smartcard_service_api
                        {
                                SCARD_DEBUG("MSG_REQUEST_CLOSE_CHANNEL");
 
-                               if (msg->callback == (void *)channel) /* synchronized call */
+                               if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
                                        channel->syncLock();
index ade55fc..3b10538 100644 (file)
@@ -161,6 +161,7 @@ namespace smartcard_service_api
                {
 #ifdef CLIENT_IPC_THREAD
                        dispatcher->processMessage(dispMsg);
+                       delete dispMsg;
 #else
                        dispatcher->pushMessage(dispMsg);
 #endif
@@ -211,6 +212,7 @@ namespace smartcard_service_api
                                {
 #ifdef CLIENT_IPC_THREAD
                                        dispatcher->processMessage(dispMsg);
+                                       delete dispMsg;
 #else
                                        dispatcher->pushMessage(dispMsg);
 #endif
index fa1c8c0..1c9c4bc 100644 (file)
@@ -36,7 +36,7 @@
 
 namespace smartcard_service_api
 {
-       Reader::Reader(void *context, char *name, void *handle):ReaderHelper()
+       Reader::Reader(void *context, const char *name, void *handle):ReaderHelper()
        {
                unsigned int length = 0;
 
@@ -59,6 +59,8 @@ namespace smartcard_service_api
                length = (length < sizeof(this->name)) ? length : sizeof(this->name);
                memcpy(this->name, name, length);
 
+               present = true;
+
 #if 0
                getPackageCert();
 #endif
@@ -91,58 +93,75 @@ namespace smartcard_service_api
 
        SessionHelper *Reader::openSessionSync()
        {
-               Message msg;
-               int rv;
+               openedSession = NULL;
+
+               if (isSecureElementPresent() == true)
+               {
+                       Message msg;
+                       int rv;
 
 #ifdef CLIENT_IPC_THREAD
-               /* request channel handle from server */
-               msg.message = Message::MSG_REQUEST_OPEN_SESSION;
-               msg.param1 = (unsigned int)handle;
-#if 0
-               msg.data = packageCert;
-#endif
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
+                       /* request channel handle from server */
+                       msg.message = Message::MSG_REQUEST_OPEN_SESSION;
+                       msg.param1 = (unsigned int)handle;
+                       msg.data = packageCert;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       ClientIPC::getInstance().sendMessage(&msg);
 
-               syncLock();
-               rv = waitTimedCondition(0);
-               syncUnlock();
+                       syncLock();
+                       rv = waitTimedCondition(0);
+                       syncUnlock();
 
-               if (rv != 0)
+                       if (rv != 0)
+                       {
+                               SCARD_DEBUG_ERR("time over");
+                       }
+#endif
+               }
+               else
                {
-                       SCARD_DEBUG_ERR("time over");
-
-                       openedSession = NULL;
+                       SCARD_DEBUG_ERR("unavailable reader");
                }
-#endif
+
                return (Session *)openedSession;
        }
 
        int Reader::openSession(openSessionCallback callback, void *userData)
        {
-               Message msg;
+               int result = -1;
 
                SCARD_BEGIN();
 
-               /* request channel handle from server */
-               msg.message = Message::MSG_REQUEST_OPEN_SESSION;
-               msg.param1 = (unsigned int)handle;
+               if (isSecureElementPresent() == true)
+               {
+                       Message msg;
+
+                       /* request channel handle from server */
+                       msg.message = Message::MSG_REQUEST_OPEN_SESSION;
+                       msg.param1 = (unsigned int)handle;
 #if 0
-               msg.data = packageCert;
+                       msg.data = packageCert;
 #endif
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)callback;
-               msg.userParam = userData;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)callback;
+                       msg.userParam = userData;
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       ClientIPC::getInstance().sendMessage(&msg);
+
+                       result = 0;
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("unavailable reader");
+               }
 
                SCARD_END();
 
-               return 0;
+               return result;
        }
 
        bool Reader::dispatcherCallback(void *message)
@@ -183,7 +202,7 @@ namespace smartcard_service_api
                                        reader->sessions.push_back(session);
                                }
 
-                               if (msg->callback == (void *)reader) /* synchronized call */
+                               if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
                                        reader->syncLock();
index 2baaa3a..02b471a 100644 (file)
@@ -309,7 +309,7 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_SHUTDOWN :
                        SCARD_DEBUG("[MSG_REQUEST_SHUTDOWN]");
 
-                       if (msg->callback == (void *)service) /* synchronized call */
+                       if (msg->isSynchronousCall() == true) /* synchronized call */
                        {
                                /* sync call */
                                service->syncLock();
@@ -330,28 +330,56 @@ namespace smartcard_service_api
                        break;
 
                case Message::MSG_NOTIFY_SE_INSERTED :
-                       SCARD_DEBUG("[MSG_NOTIFY_SE_INSERTED]");
-
-                       if (service->listener != NULL)
-                       {
-                               service->listener->eventHandler(service, (char *)msg->data.getBuffer(), 1, service->context);
-                       }
-                       else
                        {
-                               SCARD_DEBUG_ERR("service->listener is null");
+                               Reader *reader = NULL;
+
+                               SCARD_DEBUG("[MSG_NOTIFY_SE_INSERTED]");
+
+                               /* add readers */
+                               reader = new Reader(service->context, (char *)msg->data.getBuffer(), (void *)msg->param1);
+                               if (reader != NULL)
+                               {
+                                       service->readers.push_back(reader);
+                               }
+                               else
+                               {
+                                       SCARD_DEBUG_ERR("alloc failed");
+                               }
+
+                               if (service->listener != NULL)
+                               {
+                                       service->listener->eventHandler(service, (char *)msg->data.getBuffer(), 1, service->context);
+                               }
+                               else
+                               {
+                                       SCARD_DEBUG("listener is null");
+                               }
                        }
                        break;
 
                case Message::MSG_NOTIFY_SE_REMOVED :
-                       SCARD_DEBUG("[MSG_NOTIFY_SE_REMOVED]");
-
-                       if (service->listener != NULL)
                        {
-                               service->listener->eventHandler(service, (char *)msg->data.getBuffer(), 2, service->context);
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("service->listener is null");
+                               size_t i;
+
+                               SCARD_DEBUG("[MSG_NOTIFY_SE_REMOVED]");
+
+                               for (i = 0; i < service->readers.size(); i++)
+                               {
+                                       if (((Reader *)service->readers[i])->handle == (void *)msg->param1)
+                                       {
+                                               ((Reader *)service->readers[i])->present = false;
+                                               break;
+                                       }
+                               }
+
+                               if (service->listener != NULL)
+                               {
+                                       service->listener->eventHandler(service, (char *)msg->data.getBuffer(), 2, service->context);
+                               }
+                               else
+                               {
+                                       SCARD_DEBUG("listener is null");
+                               }
                        }
                        break;
 
index c8ab8bf..3eed95b 100644 (file)
@@ -72,49 +72,67 @@ namespace smartcard_service_api
 
        ByteArray Session::getATRSync()
        {
-               Message msg;
-               int rv;
+               atr.releaseBuffer();
+
+               if (getReader()->isSecureElementPresent() == true)
+               {
+                       Message msg;
+                       int rv;
 
 #ifdef CLIENT_IPC_THREAD
-               /* request channel handle from server */
-               msg.message = Message::MSG_REQUEST_GET_ATR;
-               msg.param1 = (unsigned int)handle;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
+                       /* request channel handle from server */
+                       msg.message = Message::MSG_REQUEST_GET_ATR;
+                       msg.param1 = (unsigned int)handle;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       ClientIPC::getInstance().sendMessage(&msg);
 
-               syncLock();
-               rv = waitTimedCondition(0);
-               syncUnlock();
+                       syncLock();
+                       rv = waitTimedCondition(0);
+                       syncUnlock();
 
-               if (rv != 0)
+                       if (rv != 0)
+                       {
+                               SCARD_DEBUG_ERR("time over");
+                       }
+#endif
+               }
+               else
                {
-                       SCARD_DEBUG_ERR("time over");
-
-                       atr.releaseBuffer();
+                       SCARD_DEBUG_ERR("unavailable session");
                }
-#endif
 
                return atr;
        }
 
        int Session::getATR(getATRCallback callback, void *userData)
        {
-               Message msg;
+               int result = -1;
+
+               if (getReader()->isSecureElementPresent() == true)
+               {
+                       Message msg;
+
+                       /* request channel handle from server */
+                       msg.message = Message::MSG_REQUEST_GET_ATR;
+                       msg.param1 = (unsigned int)handle;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)callback;
+                       msg.userParam = userData;
 
-               /* request channel handle from server */
-               msg.message = Message::MSG_REQUEST_GET_ATR;
-               msg.param1 = (unsigned int)handle;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)callback;
-               msg.userParam = userData;
+                       ClientIPC::getInstance().sendMessage(&msg);
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       result = 0;
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("unavailable session");
+               }
 
-               return 0;
+               return result;
        }
 
        void Session::closeSync()
@@ -174,99 +192,137 @@ namespace smartcard_service_api
 
        unsigned int Session::getChannelCountSync()
        {
-               Message msg;
-               int rv;
+               channelCount = -1;
+
+               if (getReader()->isSecureElementPresent() == true)
+               {
+                       Message msg;
+                       int rv;
 
 #ifdef CLIENT_IPC_THREAD
-               /* request channel handle from server */
-               msg.message = Message::MSG_REQUEST_GET_CHANNEL_COUNT;
-               msg.param1 = (unsigned int)handle;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
+                       /* request channel handle from server */
+                       msg.message = Message::MSG_REQUEST_GET_CHANNEL_COUNT;
+                       msg.param1 = (unsigned int)handle;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       ClientIPC::getInstance().sendMessage(&msg);
 
-               syncLock();
-               rv = waitTimedCondition(0);
-               syncUnlock();
+                       syncLock();
+                       rv = waitTimedCondition(0);
+                       syncUnlock();
 
-               if (rv != 0)
-               {
-                       SCARD_DEBUG_ERR("time over");
+                       if (rv != 0)
+                       {
+                               SCARD_DEBUG_ERR("time over");
 
-                       channelCount = -1;
-               }
+                               channelCount = -1;
+                       }
 #endif
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("unavailable session");
+               }
 
                return channelCount;
        }
 
        int Session::getChannelCount(getChannelCountCallback callback, void *userData)
        {
-               Message msg;
+               int result = -1;
 
-               msg.message = Message::MSG_REQUEST_GET_CHANNEL_COUNT;
-               msg.param1 = (unsigned int)handle;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)callback;
-               msg.userParam = userData;
+               if (getReader()->isSecureElementPresent() == true)
+               {
+                       Message msg;
+
+                       msg.message = Message::MSG_REQUEST_GET_CHANNEL_COUNT;
+                       msg.param1 = (unsigned int)handle;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)callback;
+                       msg.userParam = userData;
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       ClientIPC::getInstance().sendMessage(&msg);
 
-               return 0;
+                       result = 0;
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("unavailable session");
+               }
+
+               return result;
        }
 
        Channel *Session::openChannelSync(int id, ByteArray aid)
        {
-               Message msg;
-               int rv;
+               openedChannel = NULL;
 
-#ifdef CLIENT_IPC_THREAD
-               /* request channel handle from server */
-               msg.message = Message::MSG_REQUEST_OPEN_CHANNEL;
-               msg.param1 = id;
-               msg.param2 = (unsigned int)handle;
-               msg.data = aid;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
-
-               ClientIPC::getInstance().sendMessage(&msg);
-
-               syncLock();
-               rv = waitTimedCondition(0);
-               syncUnlock();
-
-               if (rv != 0)
+               if (getReader()->isSecureElementPresent() == true)
                {
-                       SCARD_DEBUG_ERR("time over");
+                       Message msg;
+                       int rv;
 
-                       openedChannel = NULL;
-               }
+#ifdef CLIENT_IPC_THREAD
+                       /* request channel handle from server */
+                       msg.message = Message::MSG_REQUEST_OPEN_CHANNEL;
+                       msg.param1 = id;
+                       msg.param2 = (unsigned int)handle;
+                       msg.data = aid;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
+
+                       ClientIPC::getInstance().sendMessage(&msg);
+
+                       syncLock();
+                       rv = waitTimedCondition(0);
+                       syncUnlock();
+
+                       if (rv != 0)
+                       {
+                               SCARD_DEBUG_ERR("time over");
+                       }
 #endif
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("unavailable session");
+               }
 
                return (Channel *)openedChannel;
        }
 
        int Session::openChannel(int id, ByteArray aid, openChannelCallback callback, void *userData)
        {
-               Message msg;
+               int result = -1;
 
-               /* request channel handle from server */
-               msg.message = Message::MSG_REQUEST_OPEN_CHANNEL;
-               msg.param1 = id;
-               msg.param2 = (unsigned int)handle;
-               msg.data = aid;
-               msg.error = (unsigned int)context; /* using error to context */
-               msg.caller = (void *)this;
-               msg.callback = (void *)callback;
-               msg.userParam = userData;
+               if (getReader()->isSecureElementPresent() == true)
+               {
+                       Message msg;
 
-               ClientIPC::getInstance().sendMessage(&msg);
+                       /* request channel handle from server */
+                       msg.message = Message::MSG_REQUEST_OPEN_CHANNEL;
+                       msg.param1 = id;
+                       msg.param2 = (unsigned int)handle;
+                       msg.data = aid;
+                       msg.error = (unsigned int)context; /* using error to context */
+                       msg.caller = (void *)this;
+                       msg.callback = (void *)callback;
+                       msg.userParam = userData;
 
-               return 0;
+                       ClientIPC::getInstance().sendMessage(&msg);
+
+                       result = 0;
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("unavailable session");
+               }
+
+               return result;
        }
 
        Channel *Session::openBasicChannelSync(ByteArray aid)
@@ -347,7 +403,7 @@ namespace smartcard_service_api
                                        }
                                }
 
-                               if (msg->callback == (void *)session) /* synchronized call */
+                               if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
                                        session->syncLock();
@@ -373,7 +429,7 @@ namespace smartcard_service_api
                        {
                                SCARD_DEBUG("MSG_REQUEST_GET_ATR");
 
-                               if (msg->callback == (void *)session) /* synchronized call */
+                               if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
                                        session->syncLock();
@@ -398,7 +454,7 @@ namespace smartcard_service_api
                        {
                                SCARD_DEBUG("MSG_REQUEST_CLOSE_SESSION");
 
-                               if (msg->callback == (void *)session) /* synchronized call */
+                               if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
                                        session->syncLock();
@@ -422,7 +478,7 @@ namespace smartcard_service_api
                        {
                                SCARD_DEBUG("MSG_REQUEST_GET_CHANNEL_COUNT");
 
-                               if (msg->callback == (void *)session) /* synchronized call */
+                               if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
                                        session->syncLock();
index fe55273..78c15d2 100644 (file)
@@ -42,7 +42,9 @@ namespace smartcard_service_api
                int error;
                Session *openedSession;
 
-               Reader(void *context, char *name, void *handle);
+               Reader(void *context, const char *name, void *handle);
+
+               void unavailable();
 
                static bool dispatcherCallback(void *message);
                void getPackageCert();
index f65b3da..caf84b6 100644 (file)
@@ -72,6 +72,7 @@ namespace smartcard_service_api
 
        void *DispatcherHelper::_dispatcherThreadFunc(void *data)
        {
+               int result = 0;
                DispatcherMsg *msg = NULL;
                DispatcherHelper *helper = (DispatcherHelper *)data;
 
@@ -80,7 +81,7 @@ namespace smartcard_service_api
                        helper->syncLock();
                        if ((msg = helper->fetchMessage()) == NULL)
                        {
-                               helper->waitTimedCondition(0);
+                               result = helper->waitTimedCondition(0);
                                helper->syncUnlock();
                                continue;
                        }
index aed14c3..5b97ca8 100644 (file)
@@ -31,28 +31,6 @@ namespace smartcard_service_api
        {
                memset(name, 0, sizeof(name));
                seService = NULL;
+               present = false;
        }
-
-       ReaderHelper::~ReaderHelper()
-       {
-       }
-
-       const char *ReaderHelper::getName()
-       {
-               return (const char *)name;
-       }
-
-       SEServiceHelper *ReaderHelper::getSEService()
-       {
-               return seService;
-       }
-
-       bool ReaderHelper::isSecureElementPresent()
-       {
-               /* get checkse() symbol of se library (dlsym) */
-               /* invoke checkse() and return result */
-
-               return true /* checkse() */;
-       }
-
 } /* namespace smartcard_service_api */
index 75ce09d..a5dd4d6 100644 (file)
@@ -51,13 +51,11 @@ namespace smartcard_service_api
                snprintf(buffer, sizeof(buffer), "/proc/%d/exec", pid);
                SCARD_DEBUG("pid : %d, exec : %s", pid, buffer);
 
-               if ((len = readlink(buffer, filename, sizeof(filename))) < sizeof(filename))
+               if ((len = readlink(buffer, filename, sizeof(filename) - 1)) < sizeof(filename) - 1)
                {
                        char *name = NULL;
                        ByteArray hash, result;
 
-                       filename[len] = '\0';
-
                        name = basename(filename);
                        SCARD_DEBUG("file name : %s", name);
 
index 26bcdcf..fd3d638 100644 (file)
@@ -64,6 +64,8 @@ namespace smartcard_service_api
                void deserialize(unsigned char *buffer, unsigned int length);
                void deserialize(ByteArray buffer);
 
+               inline bool isSynchronousCall() { return (caller == callback); }
+
                const char *toString();
        };
 
index ce57225..049749e 100644 (file)
@@ -41,16 +41,17 @@ namespace smartcard_service_api
                char name[30];
                vector<SessionHelper *> sessions;
                SEServiceHelper *seService;
+               bool present;
 
                ReaderHelper();
 
        public:
-               ~ReaderHelper();
+               virtual ~ReaderHelper() {}
+
+               inline const char *getName() { return name; }
+               inline SEServiceHelper *getSEService() { return seService; }
+               inline bool isSecureElementPresent() { return present; }
 
-               const char *getName();
-               SEServiceHelper *getSEService();
-               bool isSecureElementPresent();
-               
                virtual void closeSessions() = 0;
 
                virtual int openSession(openSessionCallback callback, void *userData) = 0;
diff --git a/packaging/smartcard-service b/packaging/smartcard-service
new file mode 100644 (file)
index 0000000..ec68963
--- /dev/null
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+\r
+\r
diff --git a/packaging/smartcard-service-common b/packaging/smartcard-service-common
new file mode 100644 (file)
index 0000000..ec68963
--- /dev/null
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+\r
+\r
diff --git a/packaging/smartcard-service-server b/packaging/smartcard-service-server
new file mode 100644 (file)
index 0000000..ec68963
--- /dev/null
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+\r
+\r
index 1f3d791..82a323a 100644 (file)
@@ -1,7 +1,7 @@
 Name:       smartcard-service
 Summary:    Smartcard Service FW
 Version:    0.1.0
-Release:    24
+Release:    26
 Group:      libs
 License:    Samsung Proprietary License
 Source0:    %{name}-%{version}.tar.gz
index 0e3c5a2..4b6970e 100644 (file)
@@ -287,7 +287,41 @@ namespace smartcard_service_api
                return result;
        }
 
-       unsigned int ServerResource::createSession(int socket, unsigned int context, unsigned int terminalID, vector<ByteArray> &certHashes, void *caller)
+       Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID)
+       {
+               Terminal *result = NULL;
+               map<unsigned int, unsigned int>::iterator item;
+
+               if ((item = mapReaders.find(readerID)) != mapReaders.end())
+               {
+                       result = getTerminal(item->second);
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("Terminal doesn't exist, reader ID [%d]", readerID);
+               }
+
+               return result;
+       }
+
+       unsigned int ServerResource::getTerminalID(const char *name)
+       {
+               unsigned int result = IntegerHandle::INVALID_HANDLE;
+               map<unsigned int, Terminal *>::iterator item;
+
+               for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
+               {
+                       if (strncmp(name, item->second->getName(), strlen(name)) == 0)
+                       {
+                               result = item->first;
+                               break;
+                       }
+               }
+
+               return result;
+       }
+
+       unsigned int ServerResource::createSession(int socket, unsigned int context, unsigned int readerID, vector<ByteArray> &certHashes, void *caller)
        {
                unsigned int result = -1;
                Terminal *temp = NULL;
@@ -295,7 +329,7 @@ namespace smartcard_service_api
 
                if ((instance = getService(socket, context)) != NULL)
                {
-                       if ((temp = getTerminal(terminalID)) != NULL)
+                       if ((temp = getTerminalByReaderID(readerID)) != NULL)
                        {
                                result = instance->openSession(temp, certHashes, caller);
                        }
@@ -616,6 +650,11 @@ namespace smartcard_service_api
 
                                SCARD_DEBUG("register success [%s] [%p] [%s] [%p]", library, libHandle, terminal->getName(), terminal);
 
+                               if (terminal->isSecureElementPresence() == true)
+                               {
+                                       createReader(handle);
+                               }
+
                                result = true;
                        }
                        else
@@ -698,14 +737,14 @@ namespace smartcard_service_api
 
        bool ServerResource::isValidReaderHandle(unsigned int reader)
        {
-               return (getTerminal(reader) != NULL);
+               return (getTerminalByReaderID(reader) != NULL);
        }
 
        bool ServerResource::isValidSessionHandle(int socket, unsigned int context, unsigned int session)
        {
                ServiceInstance *instance = NULL;
 
-               return (((instance = getService(socket, context)) != NULL) && (getService(socket, context)->isVaildSessionHandle(session)));
+               return (((instance = getService(socket, context)) != NULL) && (instance->isVaildSessionHandle(session)));
        }
 
        int ServerResource::getReadersInformation(ByteArray &info)
@@ -716,16 +755,24 @@ namespace smartcard_service_api
                unsigned int offset = 0;
                unsigned int nameLen = 0;
 
-               if (mapTerminals.size() > 0)
+               if (mapReaders.size() > 0)
                {
-                       map<unsigned int, Terminal *>::iterator item;
+                       Terminal *terminal = NULL;
+                       map<unsigned int, unsigned int>::iterator item;
 
-                       for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
+                       for (item = mapReaders.begin(); item != mapReaders.end(); item++)
                        {
-                               if (item->second->isSecureElementPresence())
+                               if (item->second != IntegerHandle::INVALID_HANDLE)
                                {
-                                       length += sizeof(nameLen) + strlen(item->second->getName()) + sizeof(unsigned int);
-                                       result++;
+                                       terminal = getTerminal(item->second);
+                                       if (terminal != NULL)
+                                       {
+                                               if (terminal->isSecureElementPresence())
+                                               {
+                                                       length += sizeof(nameLen) + strlen(terminal->getName()) + sizeof(unsigned int);
+                                                       result++;
+                                               }
+                                       }
                                }
                        }
 
@@ -734,20 +781,27 @@ namespace smartcard_service_api
                        {
                                memset(buffer, 0, length);
 
-                               for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
+                               for (item = mapReaders.begin(); item != mapReaders.end(); item++)
                                {
-                                       if (item->second->isSecureElementPresence())
+                                       if (item->second != IntegerHandle::INVALID_HANDLE)
                                        {
-                                               nameLen = strlen(item->second->getName());
-
-                                               memcpy(buffer + offset, &nameLen, sizeof(nameLen));
-                                               offset += sizeof(nameLen);
-
-                                               memcpy(buffer + offset, item->second->getName(), nameLen);
-                                               offset += nameLen;
-
-                                               memcpy(buffer + offset, &item->first, sizeof(unsigned int));
-                                               offset += sizeof(unsigned int);
+                                               terminal = getTerminal(item->second);
+                                               if (terminal != NULL)
+                                               {
+                                                       if (terminal->isSecureElementPresence())
+                                                       {
+                                                               nameLen = strlen(terminal->getName());
+
+                                                               memcpy(buffer + offset, &nameLen, sizeof(nameLen));
+                                                               offset += sizeof(nameLen);
+
+                                                               memcpy(buffer + offset, terminal->getName(), nameLen);
+                                                               offset += nameLen;
+
+                                                               memcpy(buffer + offset, &item->first, sizeof(unsigned int));
+                                                               offset += sizeof(unsigned int);
+                                                       }
+                                               }
                                        }
                                }
 
@@ -784,37 +838,48 @@ namespace smartcard_service_api
 
        void ServerResource::terminalCallback(void *terminal, int event, int error, void *user_param)
        {
-               SCARD_BEGIN();
+               SCARD_DEBUG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
 
                switch (event)
                {
                case Terminal::NOTIFY_SE_AVAILABLE :
                        {
+                               ServerResource &instance = ServerResource::getInstance();
+                               unsigned int terminalID = IntegerHandle::INVALID_HANDLE;
                                Message msg;
 
                                SCARD_DEBUG("[NOTIFY_SE_AVAILABLE]");
-                               SCARD_DEBUG("terminal [%s], error [%d], user_param [%p]", (char *)terminal, error, user_param);
 
-                               /* send all client to refresh reader */
-                               msg.message = msg.MSG_NOTIFY_SE_INSERTED;
-                               msg.data.setBuffer((unsigned char *)terminal, strlen((char *)terminal) + 1);
+                               terminalID = instance.getTerminalID((char *)terminal);
+                               if (terminalID != IntegerHandle::INVALID_HANDLE)
+                               {
+                                       /* send all client to refresh reader */
+                                       msg.message = msg.MSG_NOTIFY_SE_INSERTED;
+                                       msg.param1 = instance.createReader(terminalID);
+                                       msg.data.setBuffer((unsigned char *)terminal, strlen((char *)terminal) + 1);
 
-                               ServerResource::getInstance().sendMessageToAllClients(msg);
+                                       instance.sendMessageToAllClients(msg);
+                               }
                        }
                        break;
 
                case Terminal::NOTIFY_SE_NOT_AVAILABLE :
                        {
+                               ServerResource &instance = ServerResource::getInstance();
+                               unsigned int readerID = IntegerHandle::INVALID_HANDLE;
                                Message msg;
 
                                SCARD_DEBUG("[NOTIFY_SE_NOT_AVAILABLE]");
-                               SCARD_DEBUG("terminal [%s], error [%d], user_param [%p]", (char *)terminal, error, user_param);
+
+                               readerID = instance.getReaderID((char *)terminal);
 
                                /* send all client to refresh reader */
                                msg.message = msg.MSG_NOTIFY_SE_REMOVED;
+                               msg.param1 = readerID;
                                msg.data.setBuffer((unsigned char *)terminal, strlen((char *)terminal) + 1);
 
-                               ServerResource::getInstance().sendMessageToAllClients(msg);
+                               instance.sendMessageToAllClients(msg);
+                               instance.removeReader(readerID);
                        }
                        break;
 
@@ -822,8 +887,49 @@ namespace smartcard_service_api
                        SCARD_DEBUG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
                        break;
                }
+       }
 
-               SCARD_END();
+       unsigned int ServerResource::createReader(unsigned int terminalID)
+       {
+               unsigned int result = -1;
+
+               result = IntegerHandle::assignHandle();
+
+               mapReaders.insert(make_pair(result, terminalID));
+
+               return result;
+       }
+
+       unsigned int ServerResource::getReaderID(const char *name)
+       {
+               unsigned int result = IntegerHandle::INVALID_HANDLE, terminalID = IntegerHandle::INVALID_HANDLE;
+
+               terminalID = getTerminalID(name);
+               if (terminalID != IntegerHandle::INVALID_HANDLE)
+               {
+                       map<unsigned int, unsigned int>::iterator item;
+
+                       for (item = mapReaders.begin(); item != mapReaders.end(); item++)
+                       {
+                               if (item->second == terminalID)
+                               {
+                                       result = item->first;
+                                       break;
+                               }
+                       }
+               }
+
+               return result;
+       }
+
+       void ServerResource::removeReader(unsigned int readerID)
+       {
+               map<unsigned int, unsigned int>::iterator item;
+
+               if ((item = mapReaders.find(readerID)) != mapReaders.end())
+               {
+                       item->second = IntegerHandle::INVALID_HANDLE;
+               }
        }
 
 } /* namespace smartcard_service_api */
index 0cb9cc1..4479462 100644 (file)
@@ -63,7 +63,8 @@ namespace smartcard_service_api
        private:
                /* non-static member */
                vector<void *> libraries;
-               map<unsigned int, Terminal *> mapTerminals; /* unique id <-> terminal instance map */
+               map<unsigned int, Terminal *> mapTerminals; /* terminal unique id <-> terminal instance map */
+               map<unsigned int, unsigned int> mapReaders; /* reader unique id <-> terminal unique id map */
                map<int, ClientInstance *> mapClients; /* client pid <-> client instance map */
                map<Terminal *, AccessControlList *> mapACL; /* terminal instance <-> access control instance map */
                void *mainLoop;
@@ -98,9 +99,15 @@ namespace smartcard_service_api
 
                Terminal *getTerminal(unsigned int terminalID);
                Terminal *getTerminal(const char *name);
+               Terminal *getTerminalByReaderID(unsigned int readerID);
+               unsigned int getTerminalID(const char *name);
                int getReadersInformation(ByteArray &info);
                bool isValidReaderHandle(unsigned int reader);
 
+               unsigned int createReader(unsigned int terminalID);
+               unsigned int getReaderID(const char *name);
+               void removeReader(unsigned int readerID);
+
                bool createClient(void *ioChannel, int socket, int watchID, int state, int pid);
                ClientInstance *getClient(int socket);
                void setPID(int socket, int pid);
@@ -113,7 +120,7 @@ namespace smartcard_service_api
                void removeService(int socket, unsigned int context);
                void removeServices(int socket);
 
-               unsigned int createSession(int socket, unsigned int context, unsigned int terminalID, vector<ByteArray> &certHashes, void *caller);
+               unsigned int createSession(int socket, unsigned int context, unsigned int readerID, vector<ByteArray> &certHashes, void *caller);
                ServerSession *getSession(int socket, unsigned int context, unsigned int sessionID);
                unsigned int getChannelCount(int socket, unsigned int context, unsigned int sessionID);
                void removeSession(int socket, unsigned int context, unsigned int session);
diff --git a/server/include/SmartcardDbus.h b/server/include/SmartcardDbus.h
new file mode 100644 (file)
index 0000000..d6461f7
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SMARTCARDDBUS_H_
+#define SMARTCARDDBUS_H_
+
+/* standard library header */
+#include <glib-object.h>
+
+/* SLP library header */
+
+/* local header */
+
+typedef struct _Smartcard_Service Smartcard_Service;
+typedef struct _Smartcard_ServiceClass Smartcard_ServiceClass;
+
+#define SMARTCARD_SERVICE_NAME "org.tizen.smartcard_service"
+#define SMARTCARD_SERVICE_PATH "/org/tizen/smartcard_service"
+
+GType smartcard_service_get_type(void);
+
+struct _Smartcard_Service
+{
+       GObject parent;
+       int status;
+};
+
+struct _Smartcard_ServiceClass
+{
+       GObjectClass parent;
+};
+
+#define SMARTCARD_SERVICE_TYPE                         (smartcard_service_get_type ())
+#define SMARTCARD_SERVICE(object)                      (G_TYPE_CHECK_INSTANCE_CAST ((object), SMARTCARD_SERVICE_TYPE, Smartcard_Service))
+#define SMARTCARD_SERVICE_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), SMARTCARD_SERVICE_TYPE, Smartcard_Service_Class))
+#define IS_SMARTCARD_SERVICE(object)                   (G_TYPE_CHECK_INSTANCE_TYPE ((object), SMARTCARD_SERVICE_TYPE))
+#define IS_SMARTCARD_SERVICE_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), SMARTCARD_SERVICE_TYPE))
+#define SMARTCARD_SERVICE_GET_CLASS(obj)               (G_TYPE_INSTANCE_GET_CLASS ((obj), SMARTCARD_SERVICE_TYPE, Smartcard_Service_Class))
+
+typedef enum
+{
+       SMARTCARD_SERVICE_ERROR_INVALID_PRAM
+} Smartcard_Service_Error;
+
+GQuark smartcard_service_error_quark(void);
+#define SMARTCARD_SERVICE_ERROR smartcard_service_error_quark ()
+
+/**
+ *     launch the nfc-manager
+ */
+gboolean smartcard_service_launch(Smartcard_Service *smartcard_service, guint *result_val, GError **error);
+
+#endif /* SMARTCARDDBUS_H_ */
diff --git a/server/smartcard-service.service b/server/smartcard-service.service
new file mode 100644 (file)
index 0000000..30f31ed
--- /dev/null
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.tizen.smartcard_service
+Exec=/usr/bin/smartcard-daemon
diff --git a/server/smartcard-service.xml b/server/smartcard-service.xml
new file mode 100644 (file)
index 0000000..50e031d
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/org/tizen/smartcard_service">
+       <interface name="org.tizen.smartcard_service">
+               <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="smartcard_service"/>
+               <method name="launch">
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+</node>
+
diff --git a/smartcard-service-common-devel.manifest b/smartcard-service-common-devel.manifest
new file mode 100644 (file)
index 0000000..ca37499
--- /dev/null
@@ -0,0 +1,6 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
+
diff --git a/smartcard-service-devel.manifest b/smartcard-service-devel.manifest
new file mode 100644 (file)
index 0000000..ca37499
--- /dev/null
@@ -0,0 +1,6 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
+
diff --git a/test-client/test-client-sync.cpp b/test-client/test-client-sync.cpp
new file mode 100644 (file)
index 0000000..bacf022
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+* Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include "Debug.h"
+#include "SEService.h"
+#include "Reader.h"
+#include "Session.h"
+#include "APDUHelper.h"
+#include "ClientChannel.h"
+
+using namespace smartcard_service_api;
+
+typedef struct _user_context_t
+{
+       Session *clientSession;
+       SEServiceHelper *clientService;
+       Channel *clientChannel;
+}
+user_context_t;
+
+/* global variable */
+GMainLoop *loop = NULL;
+user_context_t user_context = { 0, };
+
+void testCloseCallback(int error, void *userData);
+void testTransmitCallback(unsigned char *buffer, unsigned int length, int error, void *userData);
+void testOpenChannelCallback(Channel *channel, int error, void *userData);
+void testGetATRCallback(unsigned char *atr, unsigned int length, int error, void *userData);
+void testCloseSessionCallback(int error, void *userData);
+void testOpenSessionCallback(SessionHelper *session, int error, void *userData);
+void testConnectedCallback(SEServiceHelper *service, void *context);
+
+class TestEventHandler : public SEServiceListener
+{
+       void serviceConnected(SEServiceHelper *service, void *userData)
+       {
+               SCARD_BEGIN();
+               testConnectedCallback(service, userData);
+               SCARD_END();
+       }
+
+       void eventHandler(SEServiceHelper *service, char *seName, int event, void *userData)
+       {
+               SCARD_BEGIN();
+
+               SCARD_DEBUG("event occured service [%p], seName[%p], event [%d]", service, seName, event);
+
+               SCARD_END();
+       }
+
+       void errorHandler(SEServiceHelper *service, int error, void *userData)
+       {
+               SCARD_BEGIN();
+
+               SCARD_DEBUG("error occured service [%p], error [%d]", service, error);
+
+               SCARD_END();
+       }
+};
+
+TestEventHandler testEventHandler;
+
+void testConnectedCallback(SEServiceHelper *service, void *userData)
+{
+       vector<ReaderHelper *> readers;
+       user_context_t *context = (user_context_t *)userData;
+
+       SCARD_BEGIN();
+
+       if (service != NULL)
+       {
+               SCARD_DEBUG("callback called, service [%p]", service);
+
+               context->clientService = service;
+
+               readers = service->getReaders();
+
+               if (readers.size() > 0)
+               {
+                       Reader *reader = NULL;
+
+                       reader = (Reader *)readers[0];
+
+                       SCARD_DEBUG("reader [%p]", reader);
+
+                       Session *session = (Session *)reader->openSessionSync();
+                       if (session != NULL)
+                       {
+                               SCARD_DEBUG("session [%p]", session);
+
+                               ByteArray temp;
+                               temp = session->getATRSync();
+                               SCARD_DEBUG("atr[%d] : %s", temp.getLength(), temp.toString());
+
+                               unsigned char MF[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
+                               ByteArray aid;
+
+                               aid.setBuffer(MF, sizeof(MF));
+                               ClientChannel *channel = (ClientChannel *)session->openLogicalChannelSync(aid);
+                               if (channel != NULL)
+                               {
+                                       SCARD_DEBUG("channel [%p]", channel);
+                                       ByteArray response;
+                                       ByteArray data, command;
+                                       int fid = 0x00003150;
+
+                                       response = channel->getSelectResponse();
+                                       SCARD_DEBUG("response : %s", response.toString());
+
+                                       SCARD_DEBUG("isBasicChannel() = %s", channel->isBasicChannel() ? "Basic" : "Logical");
+                                       SCARD_DEBUG("isClosed() = %s", channel->isClosed() ? "Closed" : "Opened");
+
+                                       data.setBuffer((unsigned char *)&fid, 2);
+                                       command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, data);
+                                       int error = channel->transmitSync(command, response);
+
+                                       SCARD_DEBUG("error : %d, response : %s", error, response.toString());
+
+                                       channel->closeSync();
+                               }
+                               else
+                               {
+                                       SCARD_DEBUG_ERR("openLogicalChannelSync failed");
+                               }
+
+                               session->closeSync();
+                       }
+                       else
+                       {
+                               SCARD_DEBUG_ERR("openSessionSync failed");
+                       }
+
+                       service->shutdown();
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("reader is empty");
+               }
+       }
+       else
+       {
+               SCARD_DEBUG_ERR("service is NULL");
+       }
+
+       g_main_loop_quit(loop);
+
+       SCARD_END();
+}
+
+int main(int argv, char *args[])
+{
+       SEService *service = new SEService((void *)&user_context, &testEventHandler);
+
+       loop = g_main_new(TRUE);
+       g_main_loop_run(loop);
+
+       if (service != NULL)
+               delete service;
+
+       return 0;
+}
index b0137fc..1923933 100644 (file)
@@ -58,9 +58,25 @@ class TestEventHandler : public SEServiceListener
 
        void eventHandler(SEServiceHelper *service, char *seName, int event, void *userData)
        {
+               user_context_t *context = (user_context_t *)userData;
+               vector<ReaderHelper *> readers;
+               size_t i;
+
                SCARD_BEGIN();
 
-               SCARD_DEBUG("event occured service [%p], seName[%p], event [%d]", service, seName, event);
+               SCARD_DEBUG("event occured service [%p], seName[%s], event [%d], userData [%p]", service, seName, event, userData);
+
+               readers = service->getReaders();
+
+               for (i = 0; i < readers.size(); i++)
+               {
+                       SCARD_DEBUG("Reader[%d] : name [%s], %s", i, readers[i]->getName(), readers[i]->isSecureElementPresent() ? "available" : "unavailable");
+               }
+
+               if (event == 1)
+               {
+                       testConnectedCallback(service, userData);
+               }
 
                SCARD_END();
        }