Home | History | Annotate | Download | only in Daemon
      1 /** @addtogroup MCD_MCDIMPL_DAEMON_CONHDLR
      2  * @{
      3  * @file
      4  *
      5  * MobiCore driver class.
      6  * The MobiCore driver class implements the ConnectionHandler interface.
      7  *
      8  * <!-- Copyright Giesecke & Devrient GmbH 2009 - 2012 -->
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. The name of the author may not be used to endorse or promote
     19  *    products derived from this software without specific prior
     20  *    written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     28  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 #ifndef MOBICOREDRIVER_H_
     35 #define MOBICOREDRIVER_H_
     36 
     37 #include "Server/public/ConnectionHandler.h"
     38 #include "Server/public/Server.h"
     39 
     40 #include "MobiCoreDevice.h"
     41 #include <string>
     42 #include <list>
     43 
     44 
     45 #define MAX_SERVERS 2
     46 
     47 class MobicoreDriverResources
     48 {
     49 public:
     50     Connection *conn;
     51     CWsm *pTciWsm;
     52     uint8_t *tci;
     53     uint32_t sessionId;
     54 
     55     MobicoreDriverResources(
     56         Connection *conn,
     57         uint8_t *tci,
     58         CWsm *pTciWsm,
     59         uint32_t sessionId
     60     ) {
     61         this->conn = conn;
     62         this->pTciWsm = pTciWsm;
     63         this->sessionId = sessionId;
     64     };
     65 };
     66 
     67 typedef std::list<MobicoreDriverResources *> driverResourcesList_t;
     68 
     69 class MobiCoreDriverDaemon : ConnectionHandler
     70 {
     71 
     72 public:
     73 
     74     /**
     75      * Create daemon object
     76      *
     77      * @param enableScheduler Enable NQ IRQ scheduler
     78      * @param loadMobicore Load mobicore image to DDR
     79      * @param mobicoreImage Mobicore image path
     80      * @param donateRamSize Ram donation size in bytes
     81      */
     82     MobiCoreDriverDaemon(
     83         bool enableScheduler,
     84         /**< Mobicore loading to DDR */
     85         bool loadMobicore,
     86         std::string mobicoreImage,
     87         unsigned int donateRamSize,
     88         /**< Mobicore driver loading at start-up */
     89         bool loadDriver,
     90         std::string driverPath
     91     );
     92 
     93     virtual ~MobiCoreDriverDaemon(
     94         void
     95     );
     96 
     97     void dropConnection(
     98         Connection *connection
     99     );
    100 
    101     bool handleConnection(
    102         Connection *connection
    103     );
    104 
    105     void run(
    106         void
    107     );
    108 
    109 private:
    110 
    111     MobiCoreDevice *mobiCoreDevice;
    112     /**< Flag to start/stop the scheduler */
    113     bool enableScheduler;
    114     /**< Flag to load mobicore image to DDR */
    115     bool loadMobicore;
    116     /**< Mobicore image location */
    117     std::string mobicoreImage;
    118     /**< Ram size to donate */
    119     unsigned int donateRamSize;
    120     bool loadDriver;
    121     std::string driverPath;
    122     /**< List of resources for the loaded drivers */
    123     driverResourcesList_t driverResources;
    124     /**< List of servers processing connections */
    125     Server *servers[MAX_SERVERS];
    126 
    127     size_t writeResult(
    128         Connection  *connection,
    129         mcResult_t  code
    130     );
    131 
    132     /**
    133         * Resolve a device ID to a MobiCore device.
    134         *
    135         * @param deviceId Device identifier of the device.
    136         * @return Reference to the device or NULL if device could not be found.
    137         */
    138     MobiCoreDevice *getDevice(
    139         uint32_t deviceId
    140     );
    141 
    142     /**
    143      * Load Device driver
    144      *
    145      * @param driverPath Path to the driver file
    146      * @return True for success/false for failure
    147      */
    148     bool loadDeviceDriver(
    149         std::string driverPath
    150     );
    151 
    152     void processOpenDevice(
    153         Connection *connection
    154     );
    155 
    156     void processOpenSession(
    157         Connection *connection
    158     );
    159 
    160     void processNqConnect(
    161         Connection *connection
    162     );
    163 
    164     void processCloseDevice(
    165         Connection *connection
    166     );
    167 
    168     void processNotify(
    169         Connection *connection
    170     );
    171 
    172     void processCloseSession(
    173         Connection *connection
    174     );
    175 
    176     void processMapBulkBuf(
    177         Connection *connection
    178     );
    179 
    180     void processUnmapBulkBuf(
    181         Connection *connection
    182     );
    183 
    184     void processGetVersion(
    185         Connection *connection
    186     );
    187 
    188     void processGetMobiCoreVersion(
    189         Connection *connection
    190     );
    191 };
    192 
    193 #endif /* MOBICOREDRIVER_H_ */
    194 
    195 /** @} */
    196