1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 /** 17 * @defgroup bsl_sal 18 * @ingroup bsl 19 * @brief System Abstraction Layer 20 */ 21 22 #ifndef BSL_SAL_H 23 #define BSL_SAL_H 24 25 #include <stdint.h> 26 #include <stddef.h> 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /** 33 * @ingroup bsl_sal 34 * 35 * Thread lock handle, the corresponding structure is provided by the user during registration. 36 */ 37 typedef void *BSL_SAL_ThreadLockHandle; 38 39 /** 40 * @ingroup bsl_sal 41 * 42 * Thread handle, the corresponding structure is provided by the user during registration. 43 */ 44 typedef void *BSL_SAL_ThreadId; 45 46 /** 47 * @ingroup bsl_sal 48 * 49 * mutex 50 */ 51 typedef void *BSL_SAL_Mutex; 52 53 /** 54 * @ingroup bsl_sal 55 * 56 * Condition handle, the corresponding structure is provided by the user during registration. 57 */ 58 typedef void *BSL_SAL_CondVar; 59 60 /** 61 * @ingroup bsl_sal 62 * @brief Allocate memory space. 63 * 64 * Allocate memory space. 65 * 66 * @attention None 67 * @param size [IN] Size of the allocated memory 68 * @retval If the application is successful, returned the pointer pointing to the memory. 69 * @retval If the application failed, return NULL. 70 */ 71 void *BSL_SAL_Malloc(uint32_t size); 72 73 /** 74 * @ingroup bsl_sal 75 * @brief Allocate and clear the memory space. 76 * 77 * Allocate and clear the memory space. The maximum size of UINT32_MAX is allocated. 78 * 79 * @attention num*size should not have overflow wrap. 80 * @param num [IN] Number of allocated memory. 81 * @param size [IN] Size of each memory. 82 * @retval If the application is successful, returned the pointer pointing to the memory. 83 * @retval If the application failed, return NULL. 84 */ 85 void *BSL_SAL_Calloc(uint32_t num, uint32_t size); 86 87 /** 88 * @ingroup bsl_sal 89 * @brief Duplicate the memory space. 90 * 91 * @param src Source memory address 92 * @param size Total memory size 93 * @retval If the allocation is successful, returned the pointer pointing to the memory. 94 * @retval If the allocation failed, return NULL. 95 */ 96 void *BSL_SAL_Dump(const void *src, uint32_t size); 97 98 /** 99 * @ingroup bsl_sal 100 * @brief Release the specified memory. 101 * 102 * Release the specified memory. 103 * 104 * @attention NONE. 105 * @param value [IN] Pointer to the memory space to be released. 106 */ 107 void BSL_SAL_Free(void *value); 108 109 /** 110 * @ingroup bsl_sal 111 * @brief Memory expansion 112 * 113 * Memory expansion function. 114 * 115 * @attention None. 116 * @param addr [IN] Original memory address. 117 * @param newSize [IN] Extended memory size. 118 * @param oldSize [IN] Memory size before expansion. 119 * @retval void* indicates successful, the extended memory address is returned. 120 * @retval NULL indicates failed, return NULL. 121 */ 122 void *BSL_SAL_Realloc(void *addr, uint32_t newSize, uint32_t oldSize); 123 124 /** 125 * @ingroup bsl_sal 126 * @brief Set sensitive information to zero. 127 * 128 * @param ptr [IN] Memory to be zeroed 129 * @param size [IN] Length of the memory to be zeroed out 130 */ 131 void BSL_SAL_CleanseData(void *ptr, uint32_t size); 132 133 /** 134 * @ingroup bsl_sal 135 * @brief Clear sensitive information and release memory. 136 * 137 * @param ptr [IN] Pointer to the memory to be released 138 * @param size [IN] Length of the memory to be zeroed out 139 */ 140 void BSL_SAL_ClearFree(void *ptr, uint32_t size); 141 142 #define BSL_SAL_FREE(value_) \ 143 do { \ 144 if ((value_) != NULL) { \ 145 BSL_SAL_Free((void *)(value_)); \ 146 (value_) = NULL; \ 147 } \ 148 } while (0) 149 150 #define BSL_SAL_ONCE_INIT 0 // equal to PTHREAD_ONCE_INIT, the pthread symbol is masked. 151 152 /** 153 * @ingroup bsl_sal 154 * @brief Create a thread lock. 155 * 156 * Create a thread lock. 157 * 158 * @attention none 159 * @param lock [IN/OUT] Lock handle 160 * @retval #BSL_SUCCESS, created successfully. 161 * @retval #BSL_MALLOC_FAIL, memory space is insufficient and failed to apply for process lock space. 162 * @retval #BSL_SAL_ERR_UNKNOWN, thread lock initialization failed. 163 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error, the value of lock is NULL. 164 */ 165 int32_t BSL_SAL_ThreadLockNew(BSL_SAL_ThreadLockHandle *lock); 166 167 /** 168 * @ingroup bsl_sal 169 * @brief Lock the read operation. 170 * 171 * Lock the read operation. 172 * 173 * @attention none 174 * @param lock [IN] Lock handle 175 * @retval #BSL_SUCCESS, succeeded. 176 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 177 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 178 */ 179 int32_t BSL_SAL_ThreadReadLock(BSL_SAL_ThreadLockHandle lock); 180 181 /** 182 * @ingroup bsl_sal 183 * @brief Lock the write operation. 184 * 185 * Lock the write operation. 186 * 187 * @attention none 188 * @param lock [IN] Lock handle 189 * @retval #BSL_SUCCESS, succeeded. 190 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 191 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 192 */ 193 int32_t BSL_SAL_ThreadWriteLock(BSL_SAL_ThreadLockHandle lock); 194 195 /** 196 * @ingroup bsl_sal 197 * @brief Unlock 198 * 199 * Unlock 200 * 201 * @attention unlock: Locks that have been unlocked are undefined behavior and are not allowed by default. 202 * @param lock [IN] Lock handle 203 * @retval #BSL_SUCCESS, succeeded. 204 * @retval #BSL_SAL_ERR_UNKNOWN operation failed. 205 * @retval #BSL_SAL_ERR_BAD_PARAM parameter error. The value of lock is NULL. 206 */ 207 int32_t BSL_SAL_ThreadUnlock(BSL_SAL_ThreadLockHandle lock); 208 209 /** 210 * @ingroup bsl_sal 211 * @brief Release the thread lock. 212 * 213 * Release the thread lock. 214 * 215 * @attention By default, repeated release is prohibited. 216 * @param lock [IN] Lock handle. 217 */ 218 void BSL_SAL_ThreadLockFree(BSL_SAL_ThreadLockHandle lock); 219 220 /** 221 * @ingroup bsl_sal 222 * @brief Obtain the thread ID. 223 * 224 * Obtain the thread ID. 225 * 226 * @attention none 227 * @retval Thread ID 228 */ 229 uint64_t BSL_SAL_ThreadGetId(void); 230 231 /** 232 * @ingroup bsl_sal 233 * @brief run once: Use the initialization callback. 234 * 235 * @attention This function should not be a cancel, otherwise the default implementation of run 236 * once seems to have never been called. 237 */ 238 typedef void (*BSL_SAL_ThreadInitRoutine)(void); 239 240 /** 241 * @ingroup bsl_sal 242 * @brief Execute only once. 243 * 244 * Run the init Func command only once. 245 * 246 * @attention The current version does not support registration. 247 * @param onceControl [IN] Record the execution status. 248 * @param initFunc [IN] Initialization function. 249 * @retval #BSL_SUCCESS, succeeded. 250 * @retval #BSL_SAL_ERR_BAD_PARAM, input parameter is abnormal. 251 * @retval #BSL_SAL_ERR_UNKNOWN, the default run once failed. 252 */ 253 int32_t BSL_SAL_ThreadRunOnce(uint32_t *onceControl, BSL_SAL_ThreadInitRoutine initFunc); 254 255 /** 256 * @ingroup bsl_sal 257 * @brief Create a thread. 258 * 259 * Create a thread. 260 * 261 * @attention none 262 * @param thread [IN/OUT] Thread ID 263 * @param startFunc [IN] Thread function 264 * @param arg [IN] Thread function parameters 265 * @retval #BSL_SUCCESS, created successfully. 266 * @retval #BSL_SAL_ERR_UNKNOWN, Failed to create a thread. 267 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. 268 */ 269 int32_t BSL_SAL_ThreadCreate(BSL_SAL_ThreadId *thread, void *(*startFunc)(void *), void *arg); 270 271 /** 272 * @ingroup bsl_sal 273 * @brief Close the thread. 274 * 275 * Close the thread. 276 * 277 * @attention none 278 * @param thread [IN] Thread ID 279 */ 280 void BSL_SAL_ThreadClose(BSL_SAL_ThreadId thread); 281 282 /** 283 * @ingroup bsl_sal 284 * @brief Create a condition variable. 285 * 286 * Create a condition variable. 287 * 288 * @attention none 289 * @param condVar [IN] Condition variable 290 * @retval #BSL_SUCCESS, created successfully. 291 * @retval #BSL_SAL_ERR_UNKNOWN, failed to create a condition variable. 292 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of condVar is NULL. 293 */ 294 int32_t BSL_SAL_CreateCondVar(BSL_SAL_CondVar *condVar); 295 296 /** 297 * @ingroup bsl_sal 298 * @brief The waiting time ends or the signal is obtained. 299 * 300 * The waiting time ends or the signal is obtained. 301 * 302 * @attention None 303 * @param condVar [IN] Condition variable 304 * @retval #BSL_SUCCESS, succeeded. 305 * @retval #BSL_SAL_ERR_UNKNOWN, function failure 306 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of condVar is NULL. 307 */ 308 int32_t BSL_SAL_CondSignal(BSL_SAL_CondVar condVar); 309 310 /** 311 * @ingroup bsl_sal 312 * @brief The waiting time ends or the signal is obtained. 313 * 314 * The waiting time ends or the signal is obtained. 315 * 316 * @attention None 317 * @param condMutex [IN] Mutex 318 * @param condVar [IN] Condition variable 319 * @param timeout [IN] Time 320 * @retval #BSL_SUCCESS, succeeded. 321 * @retval #BSL_SAL_ERR_UNKNOWN, fails. 322 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of condMutex or condVar is null. 323 */ 324 int32_t BSL_SAL_CondTimedwaitMs(BSL_SAL_Mutex condMutex, BSL_SAL_CondVar condVar, int32_t timeout); 325 326 /** 327 * @ingroup bsl_sal 328 * @brief Delete a condition variable. 329 * 330 * Delete a condition variable. 331 * 332 * @attention none 333 * @param condVar [IN] Condition variable 334 * @retval #BSL_SUCCESS, Succeeded in deleting the condition variable. 335 * @retval #BSL_SAL_ERR_UNKNOWN, Failed to delete the condition variable. 336 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of condVar is NULL. 337 */ 338 int32_t BSL_SAL_DeleteCondVar(BSL_SAL_CondVar condVar); 339 340 typedef void *bsl_sal_file_handle; // Pointer to file handle 341 342 /** 343 * @ingroup bsl_sal 344 * @brief Open a file. 345 * 346 * Open the file and ensure that the entered path is standardized. 347 * 348 * @attention None 349 * @param stream [OUT] File handle 350 * @param path [IN] File path 351 * @param mode [IN] Reading mode 352 * @retval #BSL_SUCCESS, succeeded. 353 * @retval #BSL_SAL_ERR_FILE_OPEN, failed to be opened. 354 * @retval #BSL_NULL_INPUT, parameter error. 355 */ 356 int32_t BSL_SAL_FileOpen(bsl_sal_file_handle *stream, const char *path, const char *mode); 357 358 /** 359 * @ingroup bsl_sal 360 * @brief Close the file. 361 * 362 * Close the file. 363 * 364 * @attention none 365 * @param stream [IN] File handle 366 * @retval NA 367 */ 368 void BSL_SAL_FileClose(bsl_sal_file_handle stream); 369 370 /** 371 * @ingroup bsl_sal 372 * @brief Read the file. 373 * 374 * Read the file. 375 * The actual memory of the interface is 1 more than the real length of the read file, 376 * which is used to add '\0' after the end of the read file content, and the outgoing parameter len is the real 377 * data length, excluding '\0'. 378 * 379 * @attention none 380 * @param stream [IN] File handle 381 * @param buffer [IN] Buffer for reading data 382 * @param size [IN] The unit of reading. 383 * @param num [IN] Number of data records to be read 384 * @param len [OUT] Read the data length. 385 * @retval #BSL_SUCCESS, succeeded. 386 * @retval #BSL_SAL_ERR_UNKNOWN, fails. 387 * @retval #BSL_NULL_INPUT, Incorrect parameter 388 */ 389 int32_t BSL_SAL_FileRead(bsl_sal_file_handle stream, void *buffer, size_t size, size_t num, size_t *len); 390 391 /** 392 * @ingroup bsl_sal 393 * @brief Write a file 394 * 395 * Write File 396 * 397 * @attention none 398 * @param stream [IN] File handle 399 * @param buffer [IN] Data to be written 400 * @param size [IN] Write the unit 401 * @param num [IN] Number of written data 402 * @retval #BSL_SUCCESS, succeeded 403 * @retval #BSL_SAL_ERR_UNKNOWN, fails 404 * @retval #BSL_NULL_INPUT, parameter error 405 */ 406 int32_t BSL_SAL_FileWrite(bsl_sal_file_handle stream, const void *buffer, size_t size, size_t num); 407 408 /** 409 * @ingroup bsl_sal 410 * @brief Obtain the file length. 411 * 412 * Obtain the file length. 413 * 414 * @attention none 415 * @param path [IN] File path 416 * @param len [OUT] File length 417 * @retval #BSL_SUCCESS, succeeded 418 * @retval #BSL_SAL_ERR_UNKNOWN, fails 419 * @retval #BSL_NULL_INPUT, parameter error 420 */ 421 int32_t BSL_SAL_FileLength(const char *path, size_t *len); 422 423 /** 424 * @ingroup bsl_sal 425 * @brief Basic time data structure definition. 426 */ 427 typedef struct { 428 uint16_t year; /**< Year. the value range is [0, 65535]. */ 429 uint8_t month; /**< Month. the value range is [1, 12]. */ 430 uint8_t day; /**< Day, the value range is [1, 31]. */ 431 uint8_t hour; /**< Hour, the value range is [0, 23]. */ 432 uint8_t minute; /**< Minute, the value range is [0, 59]. */ 433 uint16_t millSec; /**< Millisecond, the value range is [0, 999]. */ 434 uint8_t second; /**< Second, the value range is [0, 59]. */ 435 uint16_t microSec; /**< Microseconds, the value range is [0, 999]. */ 436 } BSL_TIME; 437 438 /** 439 * @ingroup bsl_sal 440 * @brief Unix Time structure definition. 441 */ 442 typedef int64_t BslUnixTime; 443 444 /** 445 * @ingroup bsl_sal 446 * @brief Prototype of the callback function for obtaining the time 447 * 448 * Prototype definition of the callback function for obtaining the time. 449 */ 450 typedef BslUnixTime (*BslTimeFunc)(void); 451 452 /** 453 * @ingroup bsl_sal 454 * @brief Interface for registering the function for obtaining the system time 455 * You can use this API to register the system time obtaining function. 456 * 457 * This interface can be registered for multiple times. After the registration is 458 * successful, the registration cannot be NULL again. 459 * Description of the time range: 460 * Users can use the Linux system at most 2038 per year. 461 * The lower limit of the time is 1970 - 1 - 1 0: 0: 0. 462 * It is recommended that users use this minimum intersection, i.e., the bounds of 463 * years are 1970-1-1 0:0:0 ~ 2038-01-19 03:14:08. 464 * 465 * @param func [IN] Register the function for obtaining the system time 466 */ 467 void BSL_SAL_SysTimeFuncReg(BslTimeFunc func); 468 469 /** 470 * @ingroup bsl_sal 471 * @brief Compare Two Dates 472 * 473 * @param dateA [IN] The first date 474 * @param dateB [IN] The second date 475 * @param diffSeconds [OUT] Number of seconds between two dates 476 * @retval BslTimeCmpResult Comparison result of two dates 477 * @retval #BSL_TIME_CMP_ERROR - Error in comparison 478 * @retval #BSL_TIME_CMP_EQUAL - The two dates are consistent. 479 * @retval #BSL_TIME_DATE_BEFORE - The first date is before the second date. 480 * @retval #BSL_TIME_DATE_AFTER - The first date is after the second 481 */ 482 int32_t BSL_SAL_DateTimeCompare(const BSL_TIME *dateA, const BSL_TIME *dateB, int64_t *diffSec); 483 484 /** 485 * @ingroup bsl_sal 486 * @brief Obtain the system time. 487 * 488 * Obtain the system time. 489 * 490 * @attention none 491 * @param sysTime [out] Time 492 * @retval #BSL_SUCCESS, obtained the time successfully. 493 * @retval #BSL_SAL_ERR_BAD_PARAM, the value of cb is null. 494 * @retval #BSL_INTERNAL_EXCEPTION, an exception occurred when obtaining the time. 495 */ 496 int32_t BSL_SAL_SysTimeGet(BSL_TIME *sysTime); 497 498 /** 499 * @ingroup bsl_sal 500 * @brief Obtain the Unix time. 501 * 502 * Obtain the Unix time. 503 * 504 * @retval Return the Unix time. 505 */ 506 BslUnixTime BSL_SAL_CurrentSysTimeGet(void); 507 508 /** 509 * @ingroup bsl_sal 510 * @brief Convert the date in the BslSysTime format to the UTC time format. 511 * 512 * Convert the date in the BslSysTime format to the UTC time format. 513 * 514 * @attention None 515 * @param dateTime [IN] Date and time 516 * @param utcTime [OUT] UTC time 517 * @retval #BSL_SUCCESS, time is successfully converted. 518 * @retval #BSL_INTERNAL_EXCEPTION, an exception occurred when obtaining the time. 519 */ 520 int32_t BSL_SAL_DateToUtcTimeConvert(const BSL_TIME *dateTime, int64_t *utcTime); 521 522 /** 523 * @ingroup bsl_sal 524 * @brief Convert the date in the BslUnixTime format to the BslSysTime format. 525 * 526 * Convert the date in the BslUnixTime format to the BslSysTime format. 527 * 528 * @attention none 529 * @param utcTime [IN] UTC time 530 * @param sysTime [OUT] BslSysTime Time 531 * @retval #BSL_SUCCESS, time is converted successfully 532 * @retval #BSL_SAL_ERR_BAD_PARAM, the value of utcTime exceeds the upper limit or the value of sysTime is null. 533 */ 534 int32_t BSL_SAL_UtcTimeToDateConvert(int64_t utcTime, BSL_TIME *sysTime); 535 536 /** 537 * @ingroup bsl_sal 538 * @brief Compare two dates, accurate to microseconds. 539 * 540 * Compare two dates, accurate to microseconds 541 * 542 * @attention None 543 * @param dateA [IN] Time 544 * @param dateB [IN] Time 545 * @retval #BslTimeCmpResult Comparison result of two dates 546 * @retval #BSL_TIME_CMP_ERROR - An error occurred in the comparison. 547 * @retval #BSL_TIME_CMP_EQUAL - The two dates are consistent. 548 * @retval #BSL_TIME_DATE_BEFORE - The first date is on the second 549 * @retval #BSL_TIME_DATE_ AFTER - The first date is after the second 550 */ 551 int32_t BSL_SAL_DateTimeCompareByUs(const BSL_TIME *dateA, const BSL_TIME *dateB); 552 553 /** 554 * @ingroup bsl_sal 555 * @brief Sleep the current thread 556 * 557 * Sleep the current thread 558 * 559 * @attention none 560 * @param time [IN] Sleep time 561 */ 562 void BSL_SAL_Sleep(uint32_t time); 563 564 /** 565 * @ingroup bsl_sal 566 * @brief Obtain the number of ticks that the system has experienced since startup. 567 * 568 * Obtain the system time. 569 * 570 * @attention none 571 * @retval Number of ticks 572 */ 573 long BSL_SAL_Tick(void); 574 575 /** 576 * @ingroup bsl_sal 577 * @brief Obtain the number of system ticks per second. 578 * 579 * Obtain the system time. 580 * 581 * @attention none 582 * @retval Number of ticks per second 583 */ 584 long BSL_SAL_TicksPerSec(void); 585 586 /** 587 * @ingroup bsl_sal_net 588 * @brief socket address. 589 * 590 * It should be defined like following union in linux, to cover various socket addresses. 591 * union SockAddr { 592 * struct sockaddr addr; 593 * struct sockaddr_in6 addrIn6; 594 * struct sockaddr_in addrIn; 595 * struct sockaddr_un addrUn; 596 * }; 597 * 598 */ 599 typedef void *BSL_SAL_SockAddr; 600 601 /** 602 * @ingroup bsl_sal 603 * @brief Socket address information 604 * 605 * It should be defined like 'struct addinfo' in linux, 606 * struct addrinfo { 607 * int ai_flags; 608 * int ai_family; 609 * int ai_socktype; 610 * int ai_protocol; 611 * socklen_t ai_addrlen; 612 * struct sockaddr *ai_addr; 613 * char *ai_canonname; 614 * struct addrinfo *ai_next; 615 * }; 616 */ 617 typedef void *BSL_SAL_SockAddrInfo; 618 619 /** 620 * @ingroup bsl_sal 621 * @brief Create a BSL_SAL_SockAddr 622 * 623 * @return New BSL_SAL_SockAddr object 624 */ 625 typedef int32_t (*BslSalSockAddrNew)(BSL_SAL_SockAddr *sockAddr); 626 627 /** 628 * @ingroup bsl_sal 629 * @brief Release the UIO_Addr object. 630 * 631 * @param uioAddr [IN] UIO_Addr object 632 */ 633 typedef void (*BslSalSockAddrFree)(BSL_SAL_SockAddr sockAddr); 634 635 /** 636 * @ingroup bsl_sal 637 * @brief Obtain the size of the BSL_SAL_SockAddr address. 638 * @details Only for internal use 639 * 640 * @param sockAddr [IN] UIO object 641 * @retval Address size, if the address is not valid, return 0 642 */ 643 typedef uint32_t (*BslSalSockAddrSize)(const BSL_SAL_SockAddr sockAddr); 644 645 /** 646 * @ingroup bsl_sal 647 * @brief Copy the BSL_SAL_SockAddr address. 648 * 649 * @param src [IN] Source address 650 * @param dst [OUT] Destination address 651 */ 652 typedef void (*BslSalSockAddrCopy)(BSL_SAL_SockAddr dst, const BSL_SAL_SockAddr src); 653 654 /** 655 * @ingroup bsl_sal 656 * @brief Socket creation interface 657 * 658 * Socket creation interface. 659 * 660 * @attention none 661 * @param af [IN] Socket specifies the protocol set. 662 * @param type [IN] Socket type 663 * @param protocol [IN] Protocol type 664 * @retval If the creation is successful, a non-negative value is returned. 665 * @retval Otherwise, a negative value is returned. 666 */ 667 int32_t BSL_SAL_Socket(int32_t af, int32_t type, int32_t protocol); 668 669 /** 670 * @ingroup bsl_sal 671 * @brief Close the socket 672 * 673 * Close the socket 674 * 675 * @attention none 676 * @param sockId [IN] Socket file descriptor ID 677 * @retval If the operation succeeds, BSL_SUCCESS is returned. 678 * @retval If the operation fails, BSL_SAL_ERR_NET_SOCKCLOSE is returned. 679 */ 680 int32_t BSL_SAL_SockClose(int32_t sockId); 681 682 /** 683 * @ingroup bsl_sal 684 * @brief Set the socket 685 * 686 * Set the socket 687 * 688 * @attention none 689 * @param sockId [IN] Socket file descriptor ID 690 * @param level [IN] Level of the option to be set. 691 * @param name [IN] Options to be set 692 * @param val [IN] Value of the option. 693 * @param len [IN] val Length 694 * @retval If the operation succeeds, BSL_SUCCESS is returned 695 * @retval If the operation fails, BSL_SAL_ERR_NET_SETSOCKOPT is returned. 696 */ 697 int32_t BSL_SAL_SetSockopt(int32_t sockId, int32_t level, int32_t name, const void *val, int32_t len); 698 699 /** 700 * @ingroup bsl_sal 701 * @brief Get the socket 702 * 703 * Get the socket 704 * 705 * @attention none 706 * @param sockId [IN] Socket file descriptor ID 707 * @param level [IN] Level of the option to be set. 708 * @param name [IN] Options to be set 709 * @param val [OUT] Value of the option. 710 * @param len [OUT] val Length 711 * @retval If the operation succeeds, BSL_SUCCESS is returned 712 */ 713 int32_t BSL_SAL_GetSockopt(int32_t sockId, int32_t level, int32_t name, void *val, int32_t *len); 714 715 /** 716 * @ingroup bsl_sal 717 * @brief Listening socket 718 * 719 * Listen socket 720 * 721 * @attention none 722 * @param sockId [IN] Socket file descriptor ID 723 * @param backlog [IN] Length of the receiving queue 724 * @retval If the operation succeeds, BSL_SUCCESS is returned. 725 * @retval If the operation fails, BSL_SAL_ERR_NET_LISTEN is returned. 726 */ 727 int32_t BSL_SAL_SockListen(int32_t sockId, int32_t backlog); 728 729 /** 730 * @ingroup bsl_sal 731 * @brief Binding a socket 732 * 733 * Binding Socket 734 * 735 * @attention None 736 * @param sockId [IN] Socket file descriptor ID 737 * @param addr [IN] Specify the address. 738 * @param len [IN] Address length 739 * @retval If the operation succeeds, BSL_SUCCESS is returned. 740 * @retval If the operation fails, BSL_SAL_ERR_NET_BIND is returned. 741 */ 742 int32_t BSL_SAL_SockBind(int32_t sockId, BSL_SAL_SockAddr addr, size_t len); 743 744 /** 745 * @ingroup bsl_sal 746 * @brief Initiate a connection. 747 * 748 * Initiate a connection. 749 * 750 * @attention none 751 * @param sockId [IN] Socket file descriptor ID 752 * @param addr [IN] Address to be connected 753 * @param len [IN] Address length 754 * @retval If the operation succeeds, BSL_SUCCESS is returned 755 * @retval If the operation fails, BSL_SAL_ERR_NET_CONNECT is returned. 756 */ 757 int32_t BSL_SAL_SockConnect(int32_t sockId, BSL_SAL_SockAddr addr, size_t len); 758 759 /** 760 * @ingroup bsl_sal 761 * @brief Send a message. 762 * 763 * Send messages 764 * 765 * @attention none 766 * @param sockId [IN] Socket file descriptor ID 767 * @param msg [IN] Message sent 768 * @param len [IN] Information length 769 * @param flags [IN] is generally set to 0. 770 * @retval If the operation succeeds, the length of the sent data is returned. 771 * @retval If the operation fails, a negative value is returned. 772 * @retval If the operation times out or the peer end disables the function, the value 0 is returned. 773 */ 774 int32_t BSL_SAL_SockSend(int32_t sockId, const void *msg, size_t len, int32_t flags); 775 776 /** 777 * @ingroup bsl_sal 778 * @brief Receive the message. 779 * 780 * Receive information 781 * 782 * @attention none 783 * @param sockfd [IN] Socket file descriptor ID 784 * @param buff [IN] Buffer for receiving information 785 * @param len [IN] Length of the buffer 786 * @param flags [IN] is generally set to 0. 787 * @retval If the operation succeeds, the received data length is returned. 788 * @retval If the operation fails, a negative value is returned. 789 * @retval If the operation times out or the peer end disables the function, the value 0 is returned. 790 */ 791 int32_t BSL_SAL_SockRecv(int32_t sockfd, void *buff, size_t len, int32_t flags); 792 793 /** 794 * @ingroup bsl_sal 795 * @brief Check the socket descriptor. 796 * 797 * Check the socket descriptor. 798 * 799 * @attention None 800 * @param nfds [IN] Total number of file descriptors that are listened on 801 * @param readfds [IN] Readable file descriptor (optional) 802 * @param writefds [IN] Descriptor of a writable file. This parameter is optional. 803 * @param exceptfds [IN] Exception file descriptor (optional) 804 * @param timeout [IN] Set the timeout interval. 805 * @retval If the operation succeeds, Number of ready descriptors are returned; 806 * @retval If the operation fails, a negative value is returned; 807 * @retval If the operation times out, 0 is returned 808 */ 809 int32_t BSL_SAL_Select(int32_t nfds, void *readfds, void *writefds, void *exceptfds, void *timeout); 810 811 /** 812 * @ingroup bsl_sal 813 * @brief Device control interface function 814 * 815 * Device control interface function 816 * 817 * @attention None 818 * @param sockId [IN] Socket file descriptor ID 819 * @param cmd [IN] Interaction protocol 820 * @param arg [IN] Parameter 821 * @retval If the operation succeeds, BSL_SUCCESS is returned. 822 * @retval If the operation fails, BSL_SAL_ERR_NET_IOCTL is returned. 823 */ 824 int32_t BSL_SAL_Ioctlsocket(int32_t sockId, long cmd, unsigned long *arg); 825 826 /** 827 * @ingroup bsl_sal 828 * @brief Obtain the last error corresponding to the socket. 829 * 830 * Obtain the last error corresponding to the socket. 831 * 832 * @attention none 833 * @retval Return the corresponding error. 834 */ 835 int32_t BSL_SAL_SockGetLastSocketError(void); 836 837 /** 838 * @ingroup bsl_sal 839 * @brief String comparison 840 * 841 * String comparison 842 * 843 * @attention None. 844 * @param str1 [IN] First string to be compared. 845 * @param str2 [IN] Second string to be compared. 846 * @retval If the parameter is abnormal, BSL_NULL_INPUT is returned. 847 * @retval If the strings are the same, 0 is returned; 848 * Otherwise, the difference between different characters is returned. 849 */ 850 int32_t BSL_SAL_StrcaseCmp(const char *str1, const char *str2); 851 852 /** 853 * @ingroup bsl_sal 854 * @brief Search for the corresponding character position in a string. 855 * 856 * Search for the corresponding character position in a string. 857 * 858 * @attention None. 859 * @param str [IN] String 860 * @param character [IN] Character to be searched for 861 * @param count [IN] Range to be found 862 * @retval If a character is found, the position of the character is returned; 863 * Otherwise, NULL is returned. 864 */ 865 void *BSL_SAL_Memchr(const char *str, int32_t character, size_t count); 866 867 /** 868 * @ingroup bsl_sal 869 * @brief Convert string to number 870 * 871 * Convert string to number 872 * 873 * @attention None. 874 * @param str [IN] String to be converted. 875 * @retval If the conversion is successful, the corresponding number is returned; 876 * Otherwise, the value 0 is returned. 877 */ 878 int32_t BSL_SAL_Atoi(const char *str); 879 880 /** 881 * @ingroup bsl_sal 882 * @brief Obtain the length of a given string. 883 * 884 * Obtain the length of a given string. 885 * 886 * @attention None. 887 * @param string [IN] String to obtain the length. 888 * @param count [IN] Maximum length 889 * @retval If the parameter is abnormal, return 0. 890 * @retval If the length of a string is greater than the count, return count. 891 * Otherwise, the actual length of the string is returned. 892 */ 893 uint32_t BSL_SAL_Strnlen(const char *string, uint32_t count); 894 895 typedef enum { 896 BSL_SAL_MEM_MALLOC = 0X0100, 897 BSL_SAL_MEM_FREE, 898 899 BSL_SAL_THREAD_LOCK_NEW_CB_FUNC = 0X0200, 900 BSL_SAL_THREAD_LOCK_FREE_CB_FUNC, 901 BSL_SAL_THREAD_LOCK_READ_LOCK_CB_FUNC, 902 BSL_SAL_THREAD_LOCK_WRITE_LOCK_CB_FUNC, 903 BSL_SAL_THREAD_LOCK_UNLOCK_CB_FUNC, 904 BSL_SAL_THREAD_GET_ID_CB_FUNC, 905 906 BSL_SAL_NET_WRITE_CB_FUNC = 0x0300, 907 BSL_SAL_NET_READ_CB_FUNC, 908 BSL_SAL_NET_SOCK_CB_FUNC, 909 BSL_SAL_NET_SOCK_CLOSE_CB_FUNC, 910 BSL_SAL_NET_SET_SOCK_OPT_CB_FUNC, 911 BSL_SAL_NET_GET_SOCK_OPT_CB_FUNC, 912 BSL_SAL_NET_SOCK_LISTEN_CB_FUNC, 913 BSL_SAL_NET_SOCK_BIND_CB_FUNC, 914 BSL_SAL_NET_SOCK_CONNECT_CB_FUNC, 915 BSL_SAL_NET_SOCK_SEND_CB_FUNC, 916 BSL_SAL_NET_SOCK_RECV_CB_FUNC, 917 BSL_SAL_NET_SELECT_CB_FUNC, 918 BSL_SAL_NET_IOCTL_CB_FUNC, 919 BSL_SAL_NET_SOCKGETLASTSOCKETERROR_CB_FUNC, 920 BSL_SAL_NET_SOCKADDR_NEW_CB_FUNC, 921 BSL_SAL_NET_SOCKADDR_FREE_CB_FUNC, 922 BSL_SAL_NET_SOCKADDR_SIZE_CB_FUNC, 923 BSL_SAL_NET_SENDTO_CB_FUNC, 924 BSL_SAL_NET_RECVFROM_CB_FUNC, 925 926 BSL_SAL_TIME_GET_UTC_TIME_CB_FUNC = 0x0400, 927 BSL_SAL_TIME_DATE_TO_STR_CONVERT_CB_FUNC, 928 BSL_SAL_TIME_SYS_TIME_GET_CB_FUNC, 929 BSL_SAL_TIME_UTC_TIME_TO_DATE_CONVERT_CB_FUNC, 930 BSL_SAL_TIME_SLEEP_CB_FUNC, 931 BSL_SAL_TIME_TICK_CB_FUNC, 932 BSL_SAL_TIME_TICK_PER_SEC_CB_FUNC, 933 934 BSL_SAL_FILE_OPEN_CB_FUNC = 0X0500, 935 BSL_SAL_FILE_READ_CB_FUNC, 936 BSL_SAL_FILE_WRITE_CB_FUNC, 937 BSL_SAL_FILE_CLOSE_CB_FUNC, 938 BSL_SAL_FILE_LENGTH_CB_FUNC, 939 940 BSL_SAL_DL_OPEN_CB_FUNC = 0x0700, 941 BSL_SAL_DL_CLOSE_CB_FUNC, 942 BSL_SAL_DL_SYM_CB_FUNC, 943 944 BSL_SAL_MAX_FUNC_CB = 0xffff 945 } BSL_SAL_CB_FUNC_TYPE; 946 947 /** 948 * @ingroup bsl_sal 949 * @brief Allocate a memory block. 950 * 951 * Allocate a memory block. 952 * 953 * @param size [IN] Size of the allocated memory. 954 * @retval: Not NULL, The start address of the allocated memory when memory is allocated successfully. 955 * @retval NULL, Memory allocation failure. 956 */ 957 typedef void *(*BslSalMalloc)(uint32_t size); 958 959 /** 960 * @ingroup bsl_sal 961 * @brief Reclaim a memory block allocated by pfMalloc. 962 * 963 * Reclaim a block of memory allocated by pfMalloc. 964 * 965 * @param addr [IN] Start address of the memory allocated by pfMalloc. 966 */ 967 typedef void (*BslSalFree)(void *addr); 968 969 /** 970 * @ingroup bsl_sal 971 * @brief Create a thread lock. 972 * 973 * Create a thread lock. 974 * 975 * @param lock [IN/OUT] Lock handle 976 * @retval #BSL_SUCCESS, created successfully. 977 * @retval #BSL_MALLOC_FAIL, memory space is insufficient and thread lock space cannot be applied for. 978 * @retval #BSL_SAL_ERR_UNKNOWN, thread lock initialization failed. 979 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 980 */ 981 typedef int32_t (*BslSalThreadLockNew)(BSL_SAL_ThreadLockHandle *lock); 982 983 /** 984 * @ingroup bsl_sal 985 * @brief Release the thread lock. 986 * 987 * Release the thread lock. Ensure that the lock can be released when other threads obtain the lock. 988 * 989 * @param lock [IN] Lock handle 990 */ 991 typedef void (*BslSalThreadLockFree)(BSL_SAL_ThreadLockHandle lock); 992 993 /** 994 * @ingroup bsl_sal 995 * @brief Lock the read operation. 996 * 997 * Lock the read operation. 998 * 999 * @param lock [IN] Lock handle 1000 * @retval #BSL_SUCCESS, succeeded. 1001 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 1002 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 1003 */ 1004 typedef int32_t (*BslSalThreadReadLock)(BSL_SAL_ThreadLockHandle lock); 1005 1006 /** 1007 * @ingroup bsl_sal 1008 * @brief Lock the write operation. 1009 * 1010 * Lock the write operation. 1011 * 1012 * @param lock [IN] Lock handle 1013 * @retval #BSL_SUCCESS, succeeded. 1014 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 1015 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 1016 */ 1017 typedef int32_t (*BslSalThreadWriteLock)(BSL_SAL_ThreadLockHandle lock); 1018 1019 /** 1020 * @ingroup bsl_sal 1021 * @brief Unlock 1022 * 1023 * Unlock 1024 * 1025 * @param lock [IN] Lock handle 1026 * @retval #BSL_SUCCESS, succeeded. 1027 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 1028 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 1029 */ 1030 typedef int32_t (*BslSalThreadUnlock)(BSL_SAL_ThreadLockHandle lock); 1031 1032 /** 1033 * @ingroup bsl_sal 1034 * @brief Obtain the thread ID. 1035 * 1036 * Obtain the thread ID. 1037 * 1038 * @retval Thread ID 1039 */ 1040 typedef uint64_t (*BslSalThreadGetId)(void); 1041 1042 /** 1043 * @ingroup bsl_sal 1044 * @brief Open the file. 1045 * 1046 * @retval #BSL_SUCCESS: succeeded. 1047 * @retval #BSL_SAL_ERR_FILE_OPEN: file open fails. 1048 * @retval #BSL_NULL_INPUT: parameter error. 1049 */ 1050 typedef int32_t (*BslSalFileOpen)(bsl_sal_file_handle *stream, const char *path, const char *mode); 1051 1052 /** 1053 * @ingroup bsl_sal 1054 * @brief Read from the file. 1055 * 1056 * @retval #BSL_SUCCESS: succeeded. 1057 * @retval #BSL_SAL_ERR_FILE_READ: file read fails. 1058 * @retval #BSL_NULL_INPUT: parameter error. 1059 */ 1060 typedef int32_t (*BslSalFileRead)(bsl_sal_file_handle stream, void *buffer, size_t size, size_t num, size_t *len); 1061 1062 /** 1063 * @ingroup bsl_sal 1064 * @brief Write to the file. 1065 * 1066 * @retval #BSL_SUCCESS: succeeded. 1067 * @retval #BSL_SAL_ERR_FILE_WRITE: file write fails. 1068 * @retval #BSL_NULL_INPUT: parameter error. 1069 */ 1070 typedef int32_t (*BslSalFileWrite)(bsl_sal_file_handle stream, const void *buffer, size_t size, size_t num); 1071 1072 /** 1073 * @ingroup bsl_sal 1074 * @brief Close the file. 1075 */ 1076 typedef void (*BslSalFileClose)(bsl_sal_file_handle stream); 1077 1078 /** 1079 * @ingroup bsl_sal 1080 * @brief Get the length of the file. 1081 * 1082 * @retval #BSL_SUCCESS: succeeded. 1083 * @retval #BSL_SAL_ERR_FILE_LENGTH: get file length fails. 1084 * @retval #BSL_NULL_INPUT: parameter error. 1085 */ 1086 typedef int32_t (*BslSalFileLength)(const char *path, size_t *len); 1087 1088 /** 1089 * @ingroup bsl_sal 1090 * @brief Get the system time. 1091 * 1092 * @retval System time in int64_t format. 1093 */ 1094 typedef int64_t (*BslSalGetSysTime)(void); 1095 1096 /** 1097 * @ingroup bsl_sal 1098 * @brief Convert date to string. 1099 * 1100 * @retval #BSL_SUCCESS: succeeded. 1101 * @retval #BSL_INTERNAL_EXCEPTION: conversion fails. 1102 */ 1103 typedef uint32_t (*BslSalDateToStrConvert)(const BSL_TIME *dateTime, char *timeStr, size_t len); 1104 1105 /** 1106 * @ingroup bsl_sal 1107 * @brief Get the system time. 1108 * 1109 * @retval #BSL_SUCCESS: succeeded. 1110 * @retval #BSL_SAL_ERR_BAD_PARAM: parameter error. 1111 * @retval #BSL_INTERNAL_EXCEPTION: an exception occurred when obtaining the time. 1112 */ 1113 typedef uint32_t (*BslSalSysTimeGet)(BSL_TIME *sysTime); 1114 1115 /** 1116 * @ingroup bsl_sal 1117 * @brief Convert UTC time to date. 1118 * 1119 * @retval #BSL_SUCCESS: succeeded. 1120 * @retval #BSL_SAL_ERR_BAD_PARAM: parameter error. 1121 */ 1122 typedef uint32_t (*BslSalUtcTimeToDateConvert)(int64_t utcTime, BSL_TIME *sysTime); 1123 1124 /** 1125 * @ingroup bsl_sal 1126 * @brief Sleep for a specified time. 1127 */ 1128 typedef void (*BslSalSleep)(uint32_t time); 1129 1130 /** 1131 * @ingroup bsl_sal 1132 * @brief Get the system tick count. 1133 * 1134 * @retval System tick count. 1135 */ 1136 typedef long (*BslSalTick)(void); 1137 1138 /** 1139 * @ingroup bsl_sal 1140 * @brief Get the number of ticks per second. 1141 * 1142 * @retval Number of ticks per second. 1143 */ 1144 typedef long (*BslSalTicksPerSec)(void); 1145 1146 /** 1147 * @ingroup bsl_sal 1148 * @brief Write data. 1149 * 1150 * @retval Positive integer: number of bytes written. 1151 * @retval Negative integer: write operation failed. 1152 */ 1153 typedef int32_t (*BslSalWrite)(int32_t fd, const void *buf, uint32_t len, int32_t *err); 1154 1155 /** 1156 * @ingroup bsl_sal 1157 * @brief Read data. 1158 * 1159 * @retval Positive integer: number of bytes read. 1160 * @retval Negative integer: read operation failed. 1161 */ 1162 typedef int32_t (*BslSalRead)(int32_t fd, void *buf, uint32_t len, int32_t *err); 1163 1164 /** 1165 * @ingroup bsl_sal 1166 * @brief Create a socket. 1167 * 1168 * @retval Non-negative integer: socket file descriptor. 1169 * @retval Negative integer: socket creation failed. 1170 */ 1171 typedef int32_t (*BslSalSocket)(int32_t af, int32_t type, int32_t protocol); 1172 1173 /** 1174 * @ingroup bsl_sal 1175 * @brief Close a socket. 1176 * 1177 * @retval #BSL_SUCCESS: succeeded. 1178 * @retval #BSL_SAL_ERR_NET_SOCKCLOSE: socket close fails. 1179 */ 1180 typedef int32_t (*BslSalSockClose)(int32_t sockId); 1181 1182 /** 1183 * @ingroup bsl_sal 1184 * @brief Set socket options. 1185 * 1186 * @retval #BSL_SUCCESS: succeeded. 1187 * @retval #BSL_SAL_ERR_NET_SETSOCKOPT: set socket option fails. 1188 */ 1189 typedef int32_t (*BslSalSetSockopt)(int32_t sockId, int32_t level, int32_t name, const void *val, int32_t len); 1190 1191 /** 1192 * @ingroup bsl_sal 1193 * @brief Get socket options. 1194 * 1195 * @retval #BSL_SUCCESS: succeeded. 1196 * @retval #BSL_SAL_ERR_NET_GETSOCKOPT: get socket option fails. 1197 */ 1198 typedef int32_t (*BslSalGetSockopt)(int32_t sockId, int32_t level, int32_t name, void *val, int32_t *len); 1199 1200 /** 1201 * @ingroup bsl_sal 1202 * @brief Listen for socket connections. 1203 * 1204 * @retval #BSL_SUCCESS: succeeded. 1205 * @retval #BSL_SAL_ERR_NET_LISTEN: socket listen fails. 1206 */ 1207 typedef int32_t (*BslSalSockListen)(int32_t sockId, int32_t backlog); 1208 1209 /** 1210 * @ingroup bsl_sal 1211 * @brief Bind a socket to an address. 1212 * 1213 * @retval #BSL_SUCCESS: succeeded. 1214 * @retval #BSL_SAL_ERR_NET_BIND: socket bind fails. 1215 */ 1216 typedef int32_t (*BslSalSockBind)(int32_t sockId, BSL_SAL_SockAddr addr, size_t len); 1217 1218 /** 1219 * @ingroup bsl_sal 1220 * @brief Connect a socket to a remote address. 1221 * 1222 * @retval #BSL_SUCCESS: succeeded. 1223 * @retval #BSL_SAL_ERR_NET_CONNECT: socket connect fails. 1224 */ 1225 typedef int32_t (*BslSalSockConnect)(int32_t sockId, BSL_SAL_SockAddr addr, size_t len); 1226 1227 /** 1228 * @ingroup bsl_sal 1229 * @brief Send data through a socket. 1230 * 1231 * @retval Positive integer: number of bytes sent. 1232 * @retval Negative integer: send operation failed. 1233 */ 1234 typedef int32_t (*BslSalSockSend)(int32_t sockId, const void *msg, size_t len, int32_t flags); 1235 1236 /** 1237 * @ingroup bsl_sal 1238 * @brief Receive data from a socket. 1239 * 1240 * @retval Positive integer: number of bytes received. 1241 * @retval Negative integer: receive operation failed. 1242 */ 1243 typedef int32_t (*BslSalSockRecv)(int32_t sockfd, void *buff, size_t len, int32_t flags); 1244 1245 /** 1246 * @ingroup bsl_sal 1247 * @brief Same as linux funciton "sendto" 1248 * 1249 * @param sock [IN] Socket descriptor. 1250 * @param buf [IN] The buffer containing the data to be sent. 1251 * @param len [IN] Length of the buffer. 1252 * @param flags [IN] The type of message transmission. 1253 * @param address [IN] Points to a sockaddr structure containing the destination address. 1254 * @param addrLen [IN] Length of the sockaddr structure. 1255 * @param err [OUT] The error code if "sendto" failed. 1256 * @return BSL_SUCCESS, success. 1257 * Otherwise, failure. 1258 */ 1259 typedef int32_t (*BslSalNetSendTo)(int32_t sock, const void *buf, size_t len, int32_t flags, void *address, int32_t addrLen, int32_t *err); 1260 1261 /** 1262 * @ingroup bsl_salZ 1263 * @brief Same as linux funciton "recvfrom" 1264 * @param sock [IN] Socket descriptor. 1265 * @param buf [IN] The buffer where the message should be stored. 1266 * @param len [IN] Length of the buffer. 1267 * @param flags [IN] The type of message transmission. 1268 * @param address [IN] A null pointer, or points to a sockaddr structure in 1269 which the sending address is to be stored. 1270 * @param addrLen [IN] Either a null pointer, if address is a null pointer, 1271 or a pointer to a socklen_t object which on input 1272 specifies the length of the supplied sockaddr 1273 structure, and on output specifies the length of the 1274 stored address. 1275 1276 * @param err [OUT] The error code if "recvfrom" failed. 1277 * @return BSL_SUCCESS, success. 1278 * Otherwise, failure. 1279 */ 1280 typedef int32_t (*BslSalNetRecvFrom)(int32_t sock, void *buf, size_t len, int32_t flags, void *address, int32_t *addrLen, int32_t *err); 1281 1282 /** 1283 * @ingroup bsl_sal 1284 * @brief Monitor multiple file descriptors for readiness. 1285 * 1286 * @retval Positive integer: number of ready descriptors. 1287 * @retval 0: timeout occurred. 1288 * @retval Negative integer: select operation failed. 1289 */ 1290 typedef int32_t (*BslSalSelect)(int32_t nfds, void *readfds, void *writefds, void *exceptfds, void *timeout); 1291 1292 /** 1293 * @ingroup bsl_sal 1294 * @brief Perform I/O control on a socket. 1295 * 1296 * @retval #BSL_SUCCESS: succeeded. 1297 * @retval #BSL_SAL_ERR_NET_IOCTL: ioctl operation fails. 1298 */ 1299 typedef int32_t (*BslSalIoctlsocket)(int32_t sockId, long cmd, unsigned long *arg); 1300 1301 /** 1302 * @ingroup bsl_sal 1303 * @brief Get the last socket error. 1304 * 1305 * @retval Error code of the last socket operation. 1306 */ 1307 typedef int32_t (*BslSalSockGetLastSocketError)(void); 1308 1309 /** 1310 * @ingroup bsl_sal 1311 * @brief Control callback functions for SAL (System Abstraction Layer). 1312 * 1313 * This function is used to control and register callback functions for different SAL modules 1314 * such as network, time, and file operations. 1315 * 1316 * @attention None 1317 * @param funcType [IN] Type of the callback function to be controlled 1318 * @param funcCb [IN] Pointer to the callback function 1319 * @retval #BSL_SUCCESS Callback function controlled successfully 1320 * @retval #BSL_SAL_ERR_BAD_PARAM Invalid function type or callback pointer 1321 * @retval Other error codes specific to the SAL module 1322 */ 1323 int32_t BSL_SAL_CallBack_Ctrl(BSL_SAL_CB_FUNC_TYPE funcType, void *funcCb); 1324 /** 1325 * @ingroup bsl_sal 1326 * @brief Load a dynamic library for dl. 1327 * 1328 * Load a dynamic library for dl. 1329 * 1330 * @attention None. 1331 * @param fileName [IN] Name of the file to be loaded. 1332 * @param handle [OUT] Pointer to store the handle of the loaded library. 1333 * @retval If the operation is successful, BSL_SUCCESS is returned; 1334 * Otherwise, an error code is returned. 1335 */ 1336 int32_t BSL_SAL_LoadLib(const char *fileName, void **handle); 1337 1338 /** 1339 * @ingroup bsl_sal 1340 * @brief Unload a dynamic library for dl. 1341 * 1342 * Unload a dynamic library for dl. 1343 * 1344 * @attention None. 1345 * @param handle [IN] Handle of the library to be unloaded. 1346 * @retval If the operation is successful, BSL_SUCCESS is returned; 1347 * Otherwise, an error code is returned. 1348 */ 1349 int32_t BSL_SAL_UnLoadLib(void *handle); 1350 1351 /** 1352 * @ingroup bsl_sal 1353 * @brief Get the address of the initialization function for dl. 1354 * 1355 * Get the address of the initialization function for dl. 1356 * 1357 * @attention None. 1358 * @param handle [IN] Handle of the loaded library. 1359 * @param funcName [IN] Name of the function. 1360 * @param func [OUT] Pointer to store the address of the function. 1361 * @retval If the operation is successful, BSL_SUCCESS is returned; 1362 * Otherwise, an error code is returned. 1363 */ 1364 int32_t BSL_SAL_GetFuncAddress(void *handle, const char *funcName, void **func); 1365 1366 // Define command enumeration 1367 typedef enum { 1368 BSL_SAL_LIB_FMT_OFF = 0, /* Do not enable named conversion */ 1369 BSL_SAL_LIB_FMT_SO = 1, 1370 BSL_SAL_LIB_FMT_LIBSO = 2, 1371 BSL_SAL_LIB_FMT_LIBDLL = 3, 1372 BSL_SAL_LIB_FMT_DLL = 4 1373 } BSL_SAL_LibFmtCmd; 1374 1375 /** 1376 * @ingroup bsl_sal 1377 * @brief Convert filename to full library path for dl. 1378 * 1379 * Convert filename to full library name for dl according to the specified format and directory. 1380 * 1381 * @attention None. 1382 * @param cmd [IN] Command specifying the conversion format. 1383 * @param fileName [IN] Original filename. 1384 * @param name [OUT] Pointer to store the converted full name. 1385 * @retval If the operation is successful, BSL_OK is returned; 1386 * Otherwise, an error code is returned. 1387 */ 1388 int32_t BSL_SAL_LibNameFormat(BSL_SAL_LibFmtCmd cmd, const char *fileName, char **name); 1389 1390 /** 1391 * @ingroup bsl_sal 1392 * @brief Loading dynamic libraries. 1393 * 1394 * Loading dynamic libraries. 1395 * 1396 * @param fileName [IN] Path of dl 1397 * @param handle [OUT] Dynamic library handle 1398 * @retval #BSL_SUCCESS Succeeded. 1399 * @retval #BSL_SAL_ERR_DL_NOT_FOUND Library file not found. 1400 * @retval #BSL_SAL_ERR_DL_LOAD_FAIL Failed to load the library. 1401 */ 1402 typedef int32_t (*BslSalLoadLib)(const char *fileName, void **handle); 1403 1404 /** 1405 * @ingroup bsl_sal 1406 * @brief Close dynamic library. 1407 * 1408 * Close dynamic library. 1409 * 1410 * @param handle [IN] Dynamic library handle 1411 * @retval #BSL_SUCCESS Succeeded. 1412 * @retval #BSL_SAL_ERR_DL_UNLOAAD_FAIL Failed to unload the library. 1413 */ 1414 typedef int32_t (*BslSalUnLoadLib)(void *handle); 1415 1416 /** 1417 * @ingroup bsl_sal 1418 * @brief Get function symbol from dynamic library. 1419 * 1420 * Get function symbol from dynamic library. 1421 * 1422 * @param handle [IN] Dynamic library handle 1423 * @param funcName [IN] Function name 1424 * @param func [OUT] Function pointer 1425 * @retval #BSL_SUCCESS Succeeded. 1426 * @retval #BSL_SAL_ERR_DL_NON_FUNCTION Symbol found but is not a function. 1427 * @retval #BSL_SAL_ERR_DL_LOOKUP_METHOD Failed to lookup the function. 1428 */ 1429 typedef int32_t (*BslSalGetFunc)(void *handle, const char *funcName, void **func); 1430 1431 #ifdef __cplusplus 1432 } 1433 #endif 1434 1435 #endif // BSL_SAL_H