• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2015 NXP Semiconductors
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *      http://www.apache.org/licenses/LICENSE-2.0
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16 #include "JcDnld.h"
17 #include "JcopOsDownload.h"
18 #include <data_types.h>
19 #include <log/log.h>
20 
21 JcopOsDwnld *jd;
22 IChannel_t *channel;
23 static bool inUse = false;
24 static INT16 jcHandle;
25 extern pJcopOs_Dwnld_Context_t gpJcopOs_Dwnld_Context;
26 /*******************************************************************************
27 **
28 ** Function:        JCDNLD_Init
29 **
30 ** Description:     Initializes the JCOP library and opens the DWP communication channel
31 **
32 ** Returns:         TRUE if ok.
33 **
34 *******************************************************************************/
JCDNLD_Init(IChannel_t * channel)35 tJBL_STATUS JCDNLD_Init(IChannel_t *channel)
36 {
37     static const char fn[] = "JCDNLD_Init";
38     BOOLEAN stat = FALSE;
39     jcHandle = EE_ERROR_OPEN_FAIL;
40     ALOGD("%s: enter", fn);
41 
42     if (inUse == true)
43     {
44         return STATUS_INUSE;
45     }
46     else if(channel == NULL)
47     {
48         return STATUS_FAILED;
49     }
50     /*TODO: inUse assignment should be with protection like using semaphore*/
51     inUse = true;
52     jd = JcopOsDwnld::getInstance();
53     stat = jd->initialize (channel);
54     if(stat != TRUE)
55     {
56         ALOGE("%s: failed", fn);
57     }
58     else
59     {
60         if((channel != NULL) &&
61            (channel->open) != NULL)
62         {
63             jcHandle = channel->open();
64             if(jcHandle == EE_ERROR_OPEN_FAIL)
65             {
66                 ALOGE("%s:Open DWP communication is failed", fn);
67                 stat = FALSE;
68             }
69             else
70             {
71                 ALOGE("%s:Open DWP communication is success", fn);
72                 stat = TRUE;
73             }
74         }
75         else
76         {
77             ALOGE("%s: NULL DWP channel", fn);
78             stat = FALSE;
79         }
80     }
81     return (stat == true)?STATUS_OK:STATUS_FAILED;
82 }
83 
84 /*******************************************************************************
85 **
86 ** Function:        JCDNLD_StartDownload
87 **
88 ** Description:     Starts the JCOP update
89 **
90 ** Returns:         SUCCESS if ok.
91 **
92 *******************************************************************************/
JCDNLD_StartDownload()93 tJBL_STATUS JCDNLD_StartDownload()
94 {
95     static const char fn[] = "JCDNLD_StartDownload";
96     tJBL_STATUS status = STATUS_FAILED;
97     BOOLEAN stat = FALSE;
98 
99     status = jd->JcopOs_Download();
100     ALOGE("%s: Exit; status=0x0%X", fn, status);
101     return status;
102 }
103 
104 /*******************************************************************************
105 **
106 ** Function:        JCDNLD_DeInit
107 **
108 ** Description:     Deinitializes the JCOP Lib
109 **
110 ** Returns:         TRUE if ok.
111 **
112 *******************************************************************************/
JCDNLD_DeInit()113 bool JCDNLD_DeInit()
114 {
115     static const char fn[] = "JCDNLD_DeInit";
116     BOOLEAN stat = FALSE;
117     ALOGD("%s: enter", fn);
118 
119     if(gpJcopOs_Dwnld_Context != NULL)
120     {
121         channel = gpJcopOs_Dwnld_Context->channel;
122         if((channel != NULL) && (channel->doeSE_JcopDownLoadReset != NULL))
123         {
124             channel->doeSE_JcopDownLoadReset();
125             if(channel->close != NULL)
126             {
127                 stat = channel->close(jcHandle);
128                 if(stat != TRUE)
129                 {
130                     ALOGE("%s:closing DWP channel is failed", fn);
131                 }
132             }
133             else
134             {
135                 ALOGE("%s: NULL fp DWP_close", fn);
136                 stat = FALSE;
137             }
138         }
139     }
140     else
141     {
142         ALOGE("%s: NULL dwnld context", fn);
143     }
144     jd->finalize();
145     /*TODO: inUse assignment should be with protection like using semaphore*/
146     inUse = false;
147     return stat;
148 }
149 
150 /*******************************************************************************
151 **
152 ** Function:        JCDNLD_CheckVersion
153 **
154 ** Description:     Check the existing JCOP OS version
155 **
156 ** Returns:         TRUE if ok.
157 **
158 *******************************************************************************/
JCDNLD_CheckVersion()159 bool JCDNLD_CheckVersion()
160 {
161 
162     /**
163      * Need to implement in case required
164      * */
165     return TRUE;
166 }
167