aboutsummaryrefslogtreecommitdiff
path: root/third_party/NXPNFC_P61_JCOP_Kit/src/JcDnld.cpp
blob: dba39719f8f85b043b513e01b4f758775bec3689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
 /*
  * Copyright (C) 2015 NXP Semiconductors
  *
  * 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 "JcDnld.h"
#include "JcopOsDownload.h"
#include <data_types.h>
#include <log/log.h>

JcopOsDwnld *jd;
IChannel_t *channel;
static bool inUse = false;
static INT16 jcHandle;
extern pJcopOs_Dwnld_Context_t gpJcopOs_Dwnld_Context;
/*******************************************************************************
**
** Function:        JCDNLD_Init
**
** Description:     Initializes the JCOP library and opens the DWP communication channel
**
** Returns:         TRUE if ok.
**
*******************************************************************************/
tJBL_STATUS JCDNLD_Init(IChannel_t *channel)
{
    static const char fn[] = "JCDNLD_Init";
    BOOLEAN stat = FALSE;
    jcHandle = EE_ERROR_OPEN_FAIL;
    ALOGD("%s: enter", fn);

    if (inUse == true)
    {
        return STATUS_INUSE;
    }
    else if(channel == NULL)
    {
        return STATUS_FAILED;
    }
    /*TODO: inUse assignment should be with protection like using semaphore*/
    inUse = true;
    jd = JcopOsDwnld::getInstance();
    stat = jd->initialize (channel);
    if(stat != TRUE)
    {
        ALOGE("%s: failed", fn);
    }
    else
    {
        if((channel != NULL) &&
           (channel->open) != NULL)
        {
            jcHandle = channel->open();
            if(jcHandle == EE_ERROR_OPEN_FAIL)
            {
                ALOGE("%s:Open DWP communication is failed", fn);
                stat = FALSE;
            }
            else
            {
                ALOGE("%s:Open DWP communication is success", fn);
                stat = TRUE;
            }
        }
        else
        {
            ALOGE("%s: NULL DWP channel", fn);
            stat = FALSE;
        }
    }
    return (stat == true)?STATUS_OK:STATUS_FAILED;
}

/*******************************************************************************
**
** Function:        JCDNLD_StartDownload
**
** Description:     Starts the JCOP update
**
** Returns:         SUCCESS if ok.
**
*******************************************************************************/
tJBL_STATUS JCDNLD_StartDownload()
{
    static const char fn[] = "JCDNLD_StartDownload";
    tJBL_STATUS status = STATUS_FAILED;
    BOOLEAN stat = FALSE;

    status = jd->JcopOs_Download();
    ALOGE("%s: Exit; status=0x0%X", fn, status);
    return status;
}

/*******************************************************************************
**
** Function:        JCDNLD_DeInit
**
** Description:     Deinitializes the JCOP Lib
**
** Returns:         TRUE if ok.
**
*******************************************************************************/
bool JCDNLD_DeInit()
{
    static const char fn[] = "JCDNLD_DeInit";
    BOOLEAN stat = FALSE;
    ALOGD("%s: enter", fn);

    if(gpJcopOs_Dwnld_Context != NULL)
    {
        channel = gpJcopOs_Dwnld_Context->channel;
        if((channel != NULL) && (channel->doeSE_JcopDownLoadReset != NULL))
        {
            channel->doeSE_JcopDownLoadReset();
            if(channel->close != NULL)
            {
                stat = channel->close(jcHandle);
                if(stat != TRUE)
                {
                    ALOGE("%s:closing DWP channel is failed", fn);
                }
            }
            else
            {
                ALOGE("%s: NULL fp DWP_close", fn);
                stat = FALSE;
            }
        }
    }
    else
    {
        ALOGE("%s: NULL dwnld context", fn);
    }
    jd->finalize();
    /*TODO: inUse assignment should be with protection like using semaphore*/
    inUse = false;
    return stat;
}

/*******************************************************************************
**
** Function:        JCDNLD_CheckVersion
**
** Description:     Check the existing JCOP OS version
**
** Returns:         TRUE if ok.
**
*******************************************************************************/
bool JCDNLD_CheckVersion()
{

    /**
     * Need to implement in case required
     * */
    return TRUE;
}