Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #include <list>
11 : #include "securec.h"
12 : #include "mmpa_api.h"
13 : #include "log/adx_log.h"
14 : #include "common/memory_utils.h"
15 : #include "common/config.h"
16 : #include "ide_os_type.h"
17 : #include "hdc_api.h"
18 :
19 : #define IDE_FREE_HDC_MSG_AND_SET_NULL(ptr) do { \
20 : if ((ptr) != nullptr) { \
21 : (void)drvHdcFreeMsg(ptr); \
22 : ptr = nullptr; \
23 : } \
24 : } while (0)
25 :
26 : using namespace IdeDaemon::Common::Config;
27 :
28 : namespace Adx {
29 : struct DataSendMsg {
30 : IdeSendBuffT buf;
31 : int32_t bufLen;
32 : uint32_t maxSendLen;
33 : };
34 :
35 : /**
36 : * @brief initial HDC client
37 : * @param client: HDC initialization handle
38 : *
39 : * @return
40 : * IDE_DAEMON_OK: init succ
41 : * IDE_DAEMON_ERROR: init failed
42 : */
43 1 : int32_t HdcClientInit(HDC_CLIENT *client)
44 : {
45 : UNUSED(client);
46 1 : return IDE_DAEMON_ERROR;
47 : }
48 :
49 : /**
50 : * @brief crete HDC client
51 : * @param [in] client : HDC initialization handle
52 : * @param [in] type : create client hdc service type
53 : * @return
54 : * IDE_DAEMON_OK: init succ
55 : * IDE_DAEMON_ERROR: init failed
56 : */
57 1 : HDC_CLIENT HdcClientCreate(drvHdcServiceType type)
58 : {
59 : UNUSED(type);
60 1 : return nullptr;
61 : }
62 :
63 : /**
64 : * @brief destroy HDC client
65 : * @param [in] client: HDC handle
66 : *
67 : * @return
68 : * IDE_DAEMON_OK: destroy succ
69 : * IDE_DAEMON_ERROR: destroy failed
70 : */
71 1 : int32_t HdcClientDestroy(HDC_CLIENT client)
72 : {
73 : UNUSED(client);
74 1 : return IDE_DAEMON_ERROR;
75 : }
76 :
77 1 : HDC_SERVER HdcServerCreate(int32_t logDevId, drvHdcServiceType type)
78 : {
79 : UNUSED(logDevId);
80 : UNUSED(type);
81 1 : return nullptr;
82 : }
83 :
84 : /**
85 : * @brief destroy HDC server
86 : * @param [in] server: HDC server handle
87 : *
88 : * @return
89 : * IDE_DAEMON_OK: destroy succ
90 : * IDE_DAEMON_ERROR: destroy failed
91 : */
92 1 : int32_t HdcServerDestroy(HDC_SERVER server)
93 : {
94 : UNUSED(server);
95 1 : return IDE_DAEMON_ERROR;
96 : }
97 :
98 1 : HDC_SESSION HdcServerAccept(HDC_SERVER server)
99 : {
100 : UNUSED(server);
101 1 : return nullptr;
102 : }
103 :
104 : /**
105 : * @brief get packet to recv_buf
106 : * @param packet: HDC packet
107 : * @param ioVec: a buffer that stores the result
108 : *
109 : * @return
110 : * IDE_DAEMON_OK: store data succ
111 : * IDE_DAEMON_ERROR: store data failed
112 : */
113 1 : int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec)
114 : {
115 : UNUSED(packet);
116 : UNUSED(ioVec);
117 1 : return IDE_DAEMON_ERROR;
118 : }
119 :
120 : /**
121 : * @brief get data from hdc session
122 : * @param session: HDC session
123 : * @param recv_buf: a buffer that stores the result
124 : * @param recv_len: the length of recv_buf
125 : * @param nb_flag: IDE_DAEMON_HDC_BLOCK: read by block mode; IDE_DAEMON_HDC_NOBLOCK: read by non-block mode
126 : *
127 : * @return
128 : * IDE_DAEMON_OK: read succ
129 : * IDE_DAEMON_ERROR: read failed
130 : */
131 3 : static int32_t HdcSessionRead(HDC_SESSION session, const IdeRecvBuffT recvBuf, const IdeI32Pt recvLen, int32_t nbFlag,
132 : uint32_t timeout)
133 : {
134 : UNUSED(session);
135 : UNUSED(timeout);
136 : UNUSED(recvBuf);
137 : UNUSED(recvLen);
138 : UNUSED(nbFlag);
139 3 : return IDE_DAEMON_ERROR;
140 : }
141 :
142 : /**
143 : * @brief get data from hdc session by block mode
144 : * @param session: HDC session
145 : * @param recv_buf: a buffer that stores the result
146 : * @param recv_len: the length of recv_buf
147 : *
148 : * @return
149 : * IDE_DAEMON_OK: read succ
150 : * IDE_DAEMON_ERROR: read failed
151 : */
152 1 : int32_t HdcRead(HDC_SESSION session, IdeRecvBuffT recvBuf, IdeI32Pt recvLen)
153 : {
154 1 : return HdcSessionRead(session, recvBuf, recvLen, IDE_DAEMON_BLOCK, 0);
155 : }
156 :
157 : /**
158 : * @brief get data from hdc session by non-block mode
159 : * @param session: HDC session
160 : * @param recv_buf: a buffer that stores the result
161 : * @param recv_len: the length of recv_buf
162 : *
163 : * @return
164 : * IDE_DAEMON_OK: read succ
165 : * IDE_DAEMON_ERROR: read failed
166 : */
167 1 : int32_t HdcReadNb(HDC_SESSION session, IdeRecvBuffT recvBuf, IdeI32Pt recvLen)
168 : {
169 1 : return HdcSessionRead(session, recvBuf, recvLen, IDE_DAEMON_NOBLOCK, 0);
170 : }
171 :
172 : /**
173 : * @brief get data from hdc session by non-block mode
174 : * @param session: HDC session
175 : * @param timeout: max wait time
176 : * @param recv_buf: a buffer that stores the result
177 : * @param recv_len: the length of recv_buf
178 : *
179 : * @return
180 : * IDE_DAEMON_OK: read succ
181 : * IDE_DAEMON_ERROR: read failed
182 : */
183 1 : int32_t HdcReadTimeout(HDC_SESSION session, uint32_t timeout, IdeRecvBuffT recvBuf, IdeI32Pt recvLen)
184 : {
185 1 : return HdcSessionRead(session, recvBuf, recvLen, IDE_DAEMON_TIMEOUT, timeout);
186 : }
187 :
188 : /**
189 : * @brief write data by hdc session
190 : * @param session: HDC session
191 : * @param buf: a buffer that store data to send
192 : * @param len: the length of buffer
193 : *
194 : * @return
195 : * IDE_DAEMON_OK: write succ
196 : * IDE_DAEMON_ERROR: write failed
197 : */
198 3 : int32_t HdcSessionWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len, int32_t flag)
199 : {
200 : UNUSED(session);
201 : UNUSED(buf);
202 : UNUSED(len);
203 : UNUSED(flag);
204 3 : return IDE_DAEMON_ERROR;
205 : }
206 :
207 : /**
208 : * @brief write data by hdc session
209 : * @param session: HDC session
210 : * @param buf: a buffer that store data to send
211 : * @param len: the length of buffer
212 : *
213 : * @return
214 : * IDE_DAEMON_OK: write succ
215 : * IDE_DAEMON_ERROR: write failed
216 : */
217 1 : int32_t HdcWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len)
218 : {
219 1 : return HdcSessionWrite(session, buf, len, IDE_DAEMON_BLOCK);
220 : }
221 :
222 : /**
223 : * @brief write data by hdc session
224 : * @param session: HDC session
225 : * @param buf: a buffer that store data to send
226 : * @param len: the length of buffer
227 : *
228 : * @return
229 : * IDE_DAEMON_OK: write succ
230 : * IDE_DAEMON_ERROR: write failed
231 : */
232 1 : int32_t HdcWriteNb(HDC_SESSION session, IdeSendBuffT buf, int32_t len)
233 : {
234 1 : return HdcSessionWrite(session, buf, len, IDE_DAEMON_NOBLOCK);
235 : }
236 :
237 : /**
238 : * @brief connect remote hdc server
239 : * @param peer_node: Node number of the node where Device is located
240 : * @param peer_devid: Device ID of the unified number in the host
241 : * @param client: HDC Client handle corresponding to the newly created Session
242 : * @param session: created session
243 : *
244 : * @return
245 : * IDE_DAEMON_OK: connect succ
246 : * IDE_DAEMON_ERROR: connect failed
247 : */
248 1 : int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client, HDC_SESSION *session)
249 : {
250 : UNUSED(peerNode);
251 : UNUSED(peerDevId);
252 : UNUSED(client);
253 : UNUSED(session);
254 1 : return IDE_DAEMON_ERROR;
255 : }
256 :
257 : /**
258 : * @brief connect remote hal hdc server
259 : * @param peer_node: Node number of the node where Device is located
260 : * @param peer_devid: Device ID of the unified number in the host
261 : * @param host_pid: pid of host app process
262 : * @param client: HDC Client handle corresponding to the newly created Session
263 : * @param session: created session
264 : *
265 : * @return
266 : * IDE_DAEMON_OK: connect succ
267 : * IDE_DAEMON_ERROR: connect failed
268 : */
269 1 : int32_t HalHdcSessionConnect(int32_t peerNode, int32_t peerDevId,
270 : int32_t hostPid, HDC_CLIENT client, HDC_SESSION *session)
271 : {
272 : UNUSED(peerNode);
273 : UNUSED(peerDevId);
274 : UNUSED(hostPid);
275 : UNUSED(client);
276 : UNUSED(session);
277 1 : return IDE_DAEMON_ERROR;
278 : }
279 :
280 :
281 : /**
282 : * @brief destroy hdc_connect session
283 : * @param session: the session created by hdc connect
284 : *
285 : * @return
286 : * IDE_DAEMON_OK: destroy succ
287 : * IDE_DAEMON_ERROR: destroy failed
288 : */
289 1 : int32_t HdcSessionDestroy(HDC_SESSION session)
290 : {
291 1 : return HdcSessionClose(session);
292 : }
293 :
294 : /**
295 : * @brief destroy hdc_accpet session
296 : * @param session: the session created by hdc_accept
297 : *
298 : * @return
299 : * IDE_DAEMON_OK: close succ
300 : * IDE_DAEMON_ERROR: close failed
301 : */
302 2 : int32_t HdcSessionClose(HDC_SESSION session)
303 : {
304 : UNUSED(session);
305 2 : return IDE_DAEMON_ERROR;
306 : }
307 :
308 : /**
309 : * @brief get hdc capacity
310 : * @param segment: hdc max segment size
311 : *
312 : * @return
313 : * IDE_DAEMON_OK: read succ
314 : * IDE_DAEMON_ERROR: read failed
315 : */
316 1 : int32_t HdcCapacity(IdeU32Pt segment)
317 : {
318 : UNUSED(segment);
319 1 : return IDE_DAEMON_ERROR;
320 : }
321 :
322 : /**
323 : * @brief get device id by HDC session
324 : * @param session: hdc session handle
325 : *
326 : * @return
327 : * IDE_DAEMON_OK: get hdc session succ
328 : * IDE_DAEMON_ERROR: get hdc session failed
329 : */
330 1 : int32_t IdeGetDevIdBySession(HDC_SESSION session, IdeI32Pt devId)
331 : {
332 : UNUSED(session);
333 : UNUSED(devId);
334 1 : return IDE_DAEMON_ERROR;
335 : }
336 :
337 : /**
338 : * @brief get env info by HDC session, is docker or not
339 : * @param session: hdc session handle
340 : * @param runEnv: 1 non-docker 2 docker
341 : *
342 : * @return
343 : * IDE_DAEMON_OK: get hdc session succ
344 : * IDE_DAEMON_ERROR: get hdc session failed
345 : */
346 1 : int32_t IdeGetRunEnvBySession(HDC_SESSION session, IdeI32Pt runEnv)
347 : {
348 : UNUSED(session);
349 : UNUSED(runEnv);
350 1 : return IDE_DAEMON_ERROR;
351 : }
352 :
353 : /**
354 : * @brief get vfid by HDC session
355 : * @param session: hdc session handle
356 : *
357 : * @return
358 : * IDE_DAEMON_OK: get hdc session succ
359 : * IDE_DAEMON_ERROR: get hdc session failed
360 : */
361 1 : int32_t IdeGetVfIdBySession(HDC_SESSION session, IdeI32Pt vfId)
362 : {
363 : UNUSED(session);
364 : UNUSED(vfId);
365 1 : return IDE_DAEMON_ERROR;
366 : }
367 :
368 : /**
369 : * @brief get pid info by HDC session
370 : * @param session: hdc session handle
371 : * @param pid: app pid
372 : *
373 : * @return
374 : * IDE_DAEMON_OK: get hdc session succ
375 : * IDE_DAEMON_ERROR: get hdc session failed
376 : */
377 1 : int32_t IdeGetPidBySession(HDC_SESSION session, IdeI32Pt pid)
378 : {
379 : UNUSED(session);
380 : UNUSED(pid);
381 1 : return IDE_DAEMON_ERROR;
382 : }
383 :
384 : /**
385 : * @brief : get attribute value by HDC session and attribute type
386 : * @param [in] : handle hdc session
387 : * @param [in] : attr attribute type
388 : * @param [out] : value attribute value
389 : * @return : IDE_DAEMON_OK succeed; IDE_DAEMON_ERROR failed
390 : */
391 1 : int32_t IdeGetAttrBySession(HDC_SESSION session, int32_t attr, IdeI32Pt value)
392 : {
393 : UNUSED(session);
394 : UNUSED(attr);
395 : UNUSED(value);
396 1 : return IDE_DAEMON_ERROR;
397 : }
398 : }
|