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