| 1 |
.. _linux.h: |
| 2 |
|
| 3 |
**linux.h** |
| 4 |
|
| 5 |
|
| 6 |
linux-specific utility functions |
| 7 |
|
| 8 |
.. c:function:: int nvme_fw_download_seq (int fd, __u32 size, __u32 xfer, __u32 offset, void *buf) |
| 9 |
|
| 10 |
Firmware download sequence |
| 11 |
|
| 12 |
**Parameters** |
| 13 |
|
| 14 |
``int fd`` |
| 15 |
File descriptor of nvme device |
| 16 |
|
| 17 |
``__u32 size`` |
| 18 |
Total size of the firmware image to transfer |
| 19 |
|
| 20 |
``__u32 xfer`` |
| 21 |
Maximum size to send with each partial transfer |
| 22 |
|
| 23 |
``__u32 offset`` |
| 24 |
Starting offset to send with this firmware download |
| 25 |
|
| 26 |
``void *buf`` |
| 27 |
Address of buffer containing all or part of the firmware image. |
| 28 |
|
| 29 |
**Return** |
| 30 |
|
| 31 |
The nvme command status if a response was received (see |
| 32 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 33 |
|
| 34 |
|
| 35 |
.. c:function:: int nvme_set_etdas (int fd, bool *changed) |
| 36 |
|
| 37 |
Set the Extended Telemetry Data Area 4 Supported bit |
| 38 |
|
| 39 |
**Parameters** |
| 40 |
|
| 41 |
``int fd`` |
| 42 |
File descriptor of nvme device |
| 43 |
|
| 44 |
``bool *changed`` |
| 45 |
boolean to indicate whether or not the host |
| 46 |
behavior support feature had been changed |
| 47 |
|
| 48 |
**Return** |
| 49 |
|
| 50 |
The nvme command status if a response was received (see |
| 51 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 52 |
|
| 53 |
|
| 54 |
.. c:function:: int nvme_clear_etdas (int fd, bool *changed) |
| 55 |
|
| 56 |
Clear the Extended Telemetry Data Area 4 Supported bit |
| 57 |
|
| 58 |
**Parameters** |
| 59 |
|
| 60 |
``int fd`` |
| 61 |
File descriptor of nvme device |
| 62 |
|
| 63 |
``bool *changed`` |
| 64 |
boolean to indicate whether or not the host |
| 65 |
behavior support feature had been changed |
| 66 |
|
| 67 |
**Return** |
| 68 |
|
| 69 |
The nvme command status if a response was received (see |
| 70 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 71 |
|
| 72 |
|
| 73 |
.. c:function:: int nvme_get_uuid_list (int fd, struct nvme_id_uuid_list *uuid_list) |
| 74 |
|
| 75 |
Returns the uuid list (if supported) |
| 76 |
|
| 77 |
**Parameters** |
| 78 |
|
| 79 |
``int fd`` |
| 80 |
File descriptor of nvme device |
| 81 |
|
| 82 |
``struct nvme_id_uuid_list *uuid_list`` |
| 83 |
UUID list returned by identify UUID |
| 84 |
|
| 85 |
**Return** |
| 86 |
|
| 87 |
The nvme command status if a response was received (see |
| 88 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 89 |
|
| 90 |
|
| 91 |
.. c:function:: int nvme_get_telemetry_max (int fd, enum nvme_telemetry_da *da, size_t *max_data_tx) |
| 92 |
|
| 93 |
Get telemetry limits |
| 94 |
|
| 95 |
**Parameters** |
| 96 |
|
| 97 |
``int fd`` |
| 98 |
File descriptor of nvme device |
| 99 |
|
| 100 |
``enum nvme_telemetry_da *da`` |
| 101 |
On success return max supported data area |
| 102 |
|
| 103 |
``size_t *max_data_tx`` |
| 104 |
On success set to max transfer chunk supported by the controller |
| 105 |
|
| 106 |
**Return** |
| 107 |
|
| 108 |
The nvme command status if a response was received (see |
| 109 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 110 |
|
| 111 |
|
| 112 |
.. c:function:: int nvme_get_telemetry_log (int fd, bool create, bool ctrl, bool rae, size_t max_data_tx, enum nvme_telemetry_da da, struct nvme_telemetry_log **log, size_t *size) |
| 113 |
|
| 114 |
Get specified telemetry log |
| 115 |
|
| 116 |
**Parameters** |
| 117 |
|
| 118 |
``int fd`` |
| 119 |
File descriptor of nvme device |
| 120 |
|
| 121 |
``bool create`` |
| 122 |
Generate new host initated telemetry capture |
| 123 |
|
| 124 |
``bool ctrl`` |
| 125 |
Get controller Initiated log |
| 126 |
|
| 127 |
``bool rae`` |
| 128 |
Retain asynchronous events |
| 129 |
|
| 130 |
``size_t max_data_tx`` |
| 131 |
Set the max data transfer size to be used retrieving telemetry. |
| 132 |
|
| 133 |
``enum nvme_telemetry_da da`` |
| 134 |
Log page data area, valid values: :c:type:`enum nvme_telemetry_da <nvme_telemetry_da>`. |
| 135 |
|
| 136 |
``struct nvme_telemetry_log **log`` |
| 137 |
On success, set to the value of the allocated and retrieved log. |
| 138 |
|
| 139 |
``size_t *size`` |
| 140 |
Ptr to the telemetry log size, so it can be returned |
| 141 |
|
| 142 |
**Description** |
| 143 |
|
| 144 |
The total size allocated can be calculated as: |
| 145 |
(nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. |
| 146 |
|
| 147 |
**Return** |
| 148 |
|
| 149 |
The nvme command status if a response was received (see |
| 150 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 151 |
|
| 152 |
|
| 153 |
.. c:function:: int nvme_get_ctrl_telemetry (int fd, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) |
| 154 |
|
| 155 |
Get controller telemetry log |
| 156 |
|
| 157 |
**Parameters** |
| 158 |
|
| 159 |
``int fd`` |
| 160 |
File descriptor of nvme device |
| 161 |
|
| 162 |
``bool rae`` |
| 163 |
Retain asynchronous events |
| 164 |
|
| 165 |
``struct nvme_telemetry_log **log`` |
| 166 |
On success, set to the value of the allocated and retrieved log. |
| 167 |
|
| 168 |
``enum nvme_telemetry_da da`` |
| 169 |
Log page data area, valid values: :c:type:`enum nvme_telemetry_da <nvme_telemetry_da>` |
| 170 |
|
| 171 |
``size_t *size`` |
| 172 |
Ptr to the telemetry log size, so it can be returned |
| 173 |
|
| 174 |
**Description** |
| 175 |
|
| 176 |
The total size allocated can be calculated as: |
| 177 |
(nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. |
| 178 |
|
| 179 |
**Return** |
| 180 |
|
| 181 |
The nvme command status if a response was received (see |
| 182 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 183 |
|
| 184 |
|
| 185 |
.. c:function:: int nvme_get_host_telemetry (int fd, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) |
| 186 |
|
| 187 |
Get host telemetry log |
| 188 |
|
| 189 |
**Parameters** |
| 190 |
|
| 191 |
``int fd`` |
| 192 |
File descriptor of nvme device |
| 193 |
|
| 194 |
``struct nvme_telemetry_log **log`` |
| 195 |
On success, set to the value of the allocated and retrieved log. |
| 196 |
|
| 197 |
``enum nvme_telemetry_da da`` |
| 198 |
Log page data area, valid values: :c:type:`enum nvme_telemetry_da <nvme_telemetry_da>` |
| 199 |
|
| 200 |
``size_t *size`` |
| 201 |
Ptr to the telemetry log size, so it can be returned |
| 202 |
|
| 203 |
**Description** |
| 204 |
|
| 205 |
The total size allocated can be calculated as: |
| 206 |
(nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. |
| 207 |
|
| 208 |
**Return** |
| 209 |
|
| 210 |
The nvme command status if a response was received (see |
| 211 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 212 |
|
| 213 |
|
| 214 |
.. c:function:: int nvme_get_new_host_telemetry (int fd, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) |
| 215 |
|
| 216 |
Get new host telemetry log |
| 217 |
|
| 218 |
**Parameters** |
| 219 |
|
| 220 |
``int fd`` |
| 221 |
File descriptor of nvme device |
| 222 |
|
| 223 |
``struct nvme_telemetry_log **log`` |
| 224 |
On success, set to the value of the allocated and retrieved log. |
| 225 |
|
| 226 |
``enum nvme_telemetry_da da`` |
| 227 |
Log page data area, valid values: :c:type:`enum nvme_telemetry_da <nvme_telemetry_da>` |
| 228 |
|
| 229 |
``size_t *size`` |
| 230 |
Ptr to the telemetry log size, so it can be returned |
| 231 |
|
| 232 |
**Description** |
| 233 |
|
| 234 |
The total size allocated can be calculated as: |
| 235 |
(nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. |
| 236 |
|
| 237 |
**Return** |
| 238 |
|
| 239 |
The nvme command status if a response was received (see |
| 240 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 241 |
|
| 242 |
|
| 243 |
.. c:function:: size_t nvme_get_ana_log_len_from_id_ctrl (const struct nvme_id_ctrl *id_ctrl, bool rgo) |
| 244 |
|
| 245 |
Retrieve maximum possible ANA log size |
| 246 |
|
| 247 |
**Parameters** |
| 248 |
|
| 249 |
``const struct nvme_id_ctrl *id_ctrl`` |
| 250 |
Controller identify data |
| 251 |
|
| 252 |
``bool rgo`` |
| 253 |
If true, return maximum log page size without NSIDs |
| 254 |
|
| 255 |
**Return** |
| 256 |
|
| 257 |
A byte limit on the size of the controller's ANA log page |
| 258 |
|
| 259 |
|
| 260 |
.. c:function:: int nvme_get_ana_log_len (int fd, size_t *analen) |
| 261 |
|
| 262 |
Retrieve size of the current ANA log |
| 263 |
|
| 264 |
**Parameters** |
| 265 |
|
| 266 |
``int fd`` |
| 267 |
File descriptor of nvme device |
| 268 |
|
| 269 |
``size_t *analen`` |
| 270 |
Pointer to where the length will be set on success |
| 271 |
|
| 272 |
**Return** |
| 273 |
|
| 274 |
The nvme command status if a response was received (see |
| 275 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 276 |
|
| 277 |
|
| 278 |
.. c:function:: int nvme_get_logical_block_size (int fd, __u32 nsid, int *blksize) |
| 279 |
|
| 280 |
Retrieve block size |
| 281 |
|
| 282 |
**Parameters** |
| 283 |
|
| 284 |
``int fd`` |
| 285 |
File descriptor of nvme device |
| 286 |
|
| 287 |
``__u32 nsid`` |
| 288 |
Namespace id |
| 289 |
|
| 290 |
``int *blksize`` |
| 291 |
Pointer to where the block size will be set on success |
| 292 |
|
| 293 |
**Return** |
| 294 |
|
| 295 |
The nvme command status if a response was received (see |
| 296 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 297 |
|
| 298 |
|
| 299 |
.. c:function:: int nvme_get_lba_status_log (int fd, bool rae, struct nvme_lba_status_log **log) |
| 300 |
|
| 301 |
Retrieve the LBA Status log page |
| 302 |
|
| 303 |
**Parameters** |
| 304 |
|
| 305 |
``int fd`` |
| 306 |
File descriptor of the nvme device |
| 307 |
|
| 308 |
``bool rae`` |
| 309 |
Retain asynchronous events |
| 310 |
|
| 311 |
``struct nvme_lba_status_log **log`` |
| 312 |
On success, set to the value of the allocated and retrieved log. |
| 313 |
|
| 314 |
**Return** |
| 315 |
|
| 316 |
The nvme command status if a response was received (see |
| 317 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 318 |
|
| 319 |
|
| 320 |
.. c:function:: int nvme_namespace_attach_ctrls (int fd, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) |
| 321 |
|
| 322 |
Attach namespace to controller(s) |
| 323 |
|
| 324 |
**Parameters** |
| 325 |
|
| 326 |
``int fd`` |
| 327 |
File descriptor of nvme device |
| 328 |
|
| 329 |
``__u32 nsid`` |
| 330 |
Namespace ID to attach |
| 331 |
|
| 332 |
``__u16 num_ctrls`` |
| 333 |
Number of controllers in ctrlist |
| 334 |
|
| 335 |
``__u16 *ctrlist`` |
| 336 |
List of controller IDs to perform the attach action |
| 337 |
|
| 338 |
**Return** |
| 339 |
|
| 340 |
The nvme command status if a response was received (see |
| 341 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 342 |
|
| 343 |
|
| 344 |
.. c:function:: int nvme_namespace_detach_ctrls (int fd, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) |
| 345 |
|
| 346 |
Detach namespace from controller(s) |
| 347 |
|
| 348 |
**Parameters** |
| 349 |
|
| 350 |
``int fd`` |
| 351 |
File descriptor of nvme device |
| 352 |
|
| 353 |
``__u32 nsid`` |
| 354 |
Namespace ID to detach |
| 355 |
|
| 356 |
``__u16 num_ctrls`` |
| 357 |
Number of controllers in ctrlist |
| 358 |
|
| 359 |
``__u16 *ctrlist`` |
| 360 |
List of controller IDs to perform the detach action |
| 361 |
|
| 362 |
**Return** |
| 363 |
|
| 364 |
The nvme command status if a response was received (see |
| 365 |
:c:type:`enum nvme_status_field <nvme_status_field>`) or -1 with errno set otherwise. |
| 366 |
|
| 367 |
|
| 368 |
.. c:function:: int nvme_open (const char *name) |
| 369 |
|
| 370 |
Open an nvme controller or namespace device |
| 371 |
|
| 372 |
**Parameters** |
| 373 |
|
| 374 |
``const char *name`` |
| 375 |
The basename of the device to open |
| 376 |
|
| 377 |
**Description** |
| 378 |
|
| 379 |
This will look for the handle in /dev/ and validate the name and filetype |
| 380 |
match linux conventions. |
| 381 |
|
| 382 |
**Return** |
| 383 |
|
| 384 |
A file descriptor for the device on a successful open, or -1 with |
| 385 |
errno set otherwise. |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
.. c:type:: enum nvme_hmac_alg |
| 391 |
|
| 392 |
HMAC algorithm |
| 393 |
|
| 394 |
**Constants** |
| 395 |
|
| 396 |
``NVME_HMAC_ALG_NONE`` |
| 397 |
No HMAC algorithm |
| 398 |
|
| 399 |
``NVME_HMAC_ALG_SHA2_256`` |
| 400 |
SHA2-256 |
| 401 |
|
| 402 |
``NVME_HMAC_ALG_SHA2_384`` |
| 403 |
SHA2-384 |
| 404 |
|
| 405 |
``NVME_HMAC_ALG_SHA2_512`` |
| 406 |
SHA2-512 |
| 407 |
|
| 408 |
|
| 409 |
.. c:function:: int nvme_gen_dhchap_key (char *hostnqn, enum nvme_hmac_alg hmac, unsigned int key_len, unsigned char *secret, unsigned char *key) |
| 410 |
|
| 411 |
DH-HMAC-CHAP key generation |
| 412 |
|
| 413 |
**Parameters** |
| 414 |
|
| 415 |
``char *hostnqn`` |
| 416 |
Host NVMe Qualified Name |
| 417 |
|
| 418 |
``enum nvme_hmac_alg hmac`` |
| 419 |
HMAC algorithm |
| 420 |
|
| 421 |
``unsigned int key_len`` |
| 422 |
Output key length |
| 423 |
|
| 424 |
``unsigned char *secret`` |
| 425 |
Secret to used for digest |
| 426 |
|
| 427 |
``unsigned char *key`` |
| 428 |
Generated DH-HMAC-CHAP key |
| 429 |
|
| 430 |
**Return** |
| 431 |
|
| 432 |
If key generation was successful the function returns 0 or |
| 433 |
-1 with errno set otherwise. |
| 434 |
|
| 435 |
|
| 436 |
.. c:function:: long nvme_lookup_keyring (const char *keyring) |
| 437 |
|
| 438 |
Lookup keyring serial number |
| 439 |
|
| 440 |
**Parameters** |
| 441 |
|
| 442 |
``const char *keyring`` |
| 443 |
Keyring name |
| 444 |
|
| 445 |
**Description** |
| 446 |
|
| 447 |
Looks up the serial number of the keyring **keyring**. |
| 448 |
|
| 449 |
**Return** |
| 450 |
|
| 451 |
The key serial number of the keyring |
| 452 |
or 0 with errno set otherwise. |
| 453 |
|
| 454 |
|
| 455 |
.. c:function:: char * nvme_describe_key_serial (long key_id) |
| 456 |
|
| 457 |
Return key description |
| 458 |
|
| 459 |
**Parameters** |
| 460 |
|
| 461 |
``long key_id`` |
| 462 |
Key serial number |
| 463 |
|
| 464 |
**Description** |
| 465 |
|
| 466 |
Fetches the description of the key or keyring identified |
| 467 |
by the serial number **key_id**. |
| 468 |
|
| 469 |
**Return** |
| 470 |
|
| 471 |
The description of **key_id** or NULL on failure. |
| 472 |
The returned string needs to be freed by the caller. |
| 473 |
|
| 474 |
|
| 475 |
.. c:function:: long nvme_lookup_key (const char *type, const char *identity) |
| 476 |
|
| 477 |
Lookup key serial number |
| 478 |
|
| 479 |
**Parameters** |
| 480 |
|
| 481 |
``const char *type`` |
| 482 |
Key type |
| 483 |
|
| 484 |
``const char *identity`` |
| 485 |
Key description |
| 486 |
|
| 487 |
**Description** |
| 488 |
|
| 489 |
Looks up the serial number of the key **identity** |
| 490 |
with type ``type`` in the current session keyring. |
| 491 |
|
| 492 |
**Return** |
| 493 |
|
| 494 |
The key serial number of the key |
| 495 |
or 0 with errno set otherwise. |
| 496 |
|
| 497 |
|
| 498 |
.. c:function:: int nvme_set_keyring (long keyring_id) |
| 499 |
|
| 500 |
Link keyring for lookup |
| 501 |
|
| 502 |
**Parameters** |
| 503 |
|
| 504 |
``long keyring_id`` |
| 505 |
Keyring id |
| 506 |
|
| 507 |
**Description** |
| 508 |
|
| 509 |
Links **keyring_id** into the session keyring such that |
| 510 |
its keys are available for further key lookups. |
| 511 |
|
| 512 |
**Return** |
| 513 |
|
| 514 |
0 on success, a negative number on error |
| 515 |
with errno set. |
| 516 |
|
| 517 |
|
| 518 |
.. c:function:: unsigned char * nvme_read_key (long keyring_id, long key_id, int *len) |
| 519 |
|
| 520 |
Read key raw data |
| 521 |
|
| 522 |
**Parameters** |
| 523 |
|
| 524 |
``long keyring_id`` |
| 525 |
Id of the keyring holding ``key_id`` |
| 526 |
|
| 527 |
``long key_id`` |
| 528 |
Key id |
| 529 |
|
| 530 |
``int *len`` |
| 531 |
Length of the returned data |
| 532 |
|
| 533 |
**Description** |
| 534 |
|
| 535 |
Links the keyring specified by **keyring_id** into the session |
| 536 |
keyring and reads the payload of the key specified by **key_id**. |
| 537 |
**len** holds the size of the returned buffer. |
| 538 |
If **keyring** is 0 the default keyring '.nvme' is used. |
| 539 |
|
| 540 |
**Return** |
| 541 |
|
| 542 |
Pointer to the payload on success, |
| 543 |
or NULL with errno set otherwise. |
| 544 |
|
| 545 |
|
| 546 |
.. c:function:: long nvme_update_key (long keyring_id, const char *key_type, const char *identity, unsigned char *key_data, int key_len) |
| 547 |
|
| 548 |
Update key raw data |
| 549 |
|
| 550 |
**Parameters** |
| 551 |
|
| 552 |
``long keyring_id`` |
| 553 |
Id of the keyring holding ``key_id`` |
| 554 |
|
| 555 |
``const char *key_type`` |
| 556 |
Type of the key to insert |
| 557 |
|
| 558 |
``const char *identity`` |
| 559 |
Key identity string |
| 560 |
|
| 561 |
``unsigned char *key_data`` |
| 562 |
Raw data of the key |
| 563 |
|
| 564 |
``int key_len`` |
| 565 |
Length of **key_data** |
| 566 |
|
| 567 |
**Description** |
| 568 |
|
| 569 |
Links the keyring specified by **keyring_id** into the session |
| 570 |
keyring and updates the key reference by **identity** with **key_data**. |
| 571 |
The old key with identity **identity** will be revoked to make it |
| 572 |
inaccessible. |
| 573 |
|
| 574 |
**Return** |
| 575 |
|
| 576 |
Key id of the new key or 0 with errno set otherwise. |
| 577 |
|
| 578 |
|
| 579 |
.. c:type:: nvme_scan_tls_keys_cb_t |
| 580 |
|
| 581 |
**Typedef**: Callback for iterating TLS keys |
| 582 |
|
| 583 |
|
| 584 |
**Syntax** |
| 585 |
|
| 586 |
``void nvme_scan_tls_keys_cb_t (long keyring, long key, char *desc, int desc_len, void *data)`` |
| 587 |
|
| 588 |
**Parameters** |
| 589 |
|
| 590 |
``long keyring`` |
| 591 |
Keyring which has been iterated |
| 592 |
|
| 593 |
``long key`` |
| 594 |
Key for which the callback has been invoked |
| 595 |
|
| 596 |
``char *desc`` |
| 597 |
Description of the key |
| 598 |
|
| 599 |
``int desc_len`` |
| 600 |
Length of **desc** |
| 601 |
|
| 602 |
``void *data`` |
| 603 |
Pointer for caller data |
| 604 |
|
| 605 |
**Description** |
| 606 |
|
| 607 |
Called for each TLS PSK in the keyring. |
| 608 |
|
| 609 |
|
| 610 |
.. c:function:: int nvme_scan_tls_keys (const char *keyring, nvme_scan_tls_keys_cb_t cb, void *data) |
| 611 |
|
| 612 |
Iterate over TLS keys in a keyring |
| 613 |
|
| 614 |
**Parameters** |
| 615 |
|
| 616 |
``const char *keyring`` |
| 617 |
Keyring holding TLS keys |
| 618 |
|
| 619 |
``nvme_scan_tls_keys_cb_t cb`` |
| 620 |
Callback function |
| 621 |
|
| 622 |
``void *data`` |
| 623 |
Pointer for data to be passed to **cb** |
| 624 |
|
| 625 |
**Description** |
| 626 |
|
| 627 |
Iterates **keyring** and call **cb** for each TLS key. When **keyring** is NULL |
| 628 |
the default '.nvme' keyring is used. |
| 629 |
A TLS key must be of type 'psk' and the description must be of the |
| 630 |
form 'NVMe<0|1><R|G>0<1|2> <identity>', otherwise it will be skipped |
| 631 |
during iteration. |
| 632 |
|
| 633 |
**Return** |
| 634 |
|
| 635 |
Number of keys for which **cb** was called, or -1 with errno set |
| 636 |
on error. |
| 637 |
|
| 638 |
|
| 639 |
.. c:function:: long nvme_insert_tls_key (const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int hmac, unsigned char *configured_key, int key_len) |
| 640 |
|
| 641 |
Derive and insert TLS key |
| 642 |
|
| 643 |
**Parameters** |
| 644 |
|
| 645 |
``const char *keyring`` |
| 646 |
Keyring to use |
| 647 |
|
| 648 |
``const char *key_type`` |
| 649 |
Type of the resulting key |
| 650 |
|
| 651 |
``const char *hostnqn`` |
| 652 |
Host NVMe Qualified Name |
| 653 |
|
| 654 |
``const char *subsysnqn`` |
| 655 |
Subsystem NVMe Qualified Name |
| 656 |
|
| 657 |
``int hmac`` |
| 658 |
HMAC algorithm |
| 659 |
|
| 660 |
``unsigned char *configured_key`` |
| 661 |
Configured key data to derive the key from |
| 662 |
|
| 663 |
``int key_len`` |
| 664 |
Length of **configured_key** |
| 665 |
|
| 666 |
**Description** |
| 667 |
|
| 668 |
Derives a 'retained' TLS key as specified in NVMe TCP 1.0a and |
| 669 |
stores it as type **key_type** in the keyring specified by **keyring**. |
| 670 |
|
| 671 |
**Return** |
| 672 |
|
| 673 |
The key serial number if the key could be inserted into |
| 674 |
the keyring or 0 with errno otherwise. |
| 675 |
|
| 676 |
|
| 677 |
.. c:function:: long nvme_insert_tls_key_versioned (const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len) |
| 678 |
|
| 679 |
Derive and insert TLS key |
| 680 |
|
| 681 |
**Parameters** |
| 682 |
|
| 683 |
``const char *keyring`` |
| 684 |
Keyring to use |
| 685 |
|
| 686 |
``const char *key_type`` |
| 687 |
Type of the resulting key |
| 688 |
|
| 689 |
``const char *hostnqn`` |
| 690 |
Host NVMe Qualified Name |
| 691 |
|
| 692 |
``const char *subsysnqn`` |
| 693 |
Subsystem NVMe Qualified Name |
| 694 |
|
| 695 |
``int version`` |
| 696 |
Key version to use |
| 697 |
|
| 698 |
``int hmac`` |
| 699 |
HMAC algorithm |
| 700 |
|
| 701 |
``unsigned char *configured_key`` |
| 702 |
Configured key data to derive the key from |
| 703 |
|
| 704 |
``int key_len`` |
| 705 |
Length of **configured_key** |
| 706 |
|
| 707 |
**Description** |
| 708 |
|
| 709 |
Derives a 'retained' TLS key as specified in NVMe TCP 1.0a (if |
| 710 |
**version** s set to '0') or NVMe TP8028 (if **version** is set to '1) and |
| 711 |
stores it as type **key_type** in the keyring specified by **keyring**. |
| 712 |
|
| 713 |
**Return** |
| 714 |
|
| 715 |
The key serial number if the key could be inserted into |
| 716 |
the keyring or 0 with errno otherwise. |
| 717 |
|
| 718 |
|
| 719 |
.. c:function:: long nvme_insert_tls_key_compat (const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len) |
| 720 |
|
| 721 |
Derive and insert TLS key |
| 722 |
|
| 723 |
**Parameters** |
| 724 |
|
| 725 |
``const char *keyring`` |
| 726 |
Keyring to use |
| 727 |
|
| 728 |
``const char *key_type`` |
| 729 |
Type of the resulting key |
| 730 |
|
| 731 |
``const char *hostnqn`` |
| 732 |
Host NVMe Qualified Name |
| 733 |
|
| 734 |
``const char *subsysnqn`` |
| 735 |
Subsystem NVMe Qualified Name |
| 736 |
|
| 737 |
``int version`` |
| 738 |
Key version to use |
| 739 |
|
| 740 |
``int hmac`` |
| 741 |
HMAC algorithm |
| 742 |
|
| 743 |
``unsigned char *configured_key`` |
| 744 |
Configured key data to derive the key from |
| 745 |
|
| 746 |
``int key_len`` |
| 747 |
Length of **configured_key** |
| 748 |
|
| 749 |
**Description** |
| 750 |
|
| 751 |
Derives a 'retained' TLS key as specified in NVMe TCP 1.0a (if |
| 752 |
**version** s set to '0') or NVMe TP8028 (if **version** is set to '1) and |
| 753 |
stores it as type **key_type** in the keyring specified by **keyring**. |
| 754 |
This version differs from **nvme_insert_tls_key_versioned\(\)** in that it |
| 755 |
uses the original implementation for HKDF Expand-Label which does not |
| 756 |
prefix the 'info' and 'label' strings with the length. |
| 757 |
|
| 758 |
**Return** |
| 759 |
|
| 760 |
The key serial number if the key could be inserted into |
| 761 |
the keyring or 0 with errno otherwise. |
| 762 |
|
| 763 |
|
| 764 |
.. c:function:: char * nvme_generate_tls_key_identity (const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len) |
| 765 |
|
| 766 |
Generate the TLS key identity |
| 767 |
|
| 768 |
**Parameters** |
| 769 |
|
| 770 |
``const char *hostnqn`` |
| 771 |
Host NVMe Qualified Name |
| 772 |
|
| 773 |
``const char *subsysnqn`` |
| 774 |
Subsystem NVMe Qualified Name |
| 775 |
|
| 776 |
``int version`` |
| 777 |
Key version to use |
| 778 |
|
| 779 |
``int hmac`` |
| 780 |
HMAC algorithm |
| 781 |
|
| 782 |
``unsigned char *configured_key`` |
| 783 |
Configured key data to derive the key from |
| 784 |
|
| 785 |
``int key_len`` |
| 786 |
Length of **configured_key** |
| 787 |
|
| 788 |
**Description** |
| 789 |
|
| 790 |
Derives a 'retained' TLS key as specified in NVMe TCP and |
| 791 |
generate the corresponding TLs identity. |
| 792 |
|
| 793 |
**Return** |
| 794 |
|
| 795 |
The string containing the TLS identity. It is the responsibility |
| 796 |
of the caller to free the returned string. On error NULL is returned with |
| 797 |
errno set. |
| 798 |
|
| 799 |
|
| 800 |
.. c:function:: char * nvme_generate_tls_key_identity_compat (const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len) |
| 801 |
|
| 802 |
Generate the TLS key identity |
| 803 |
|
| 804 |
**Parameters** |
| 805 |
|
| 806 |
``const char *hostnqn`` |
| 807 |
Host NVMe Qualified Name |
| 808 |
|
| 809 |
``const char *subsysnqn`` |
| 810 |
Subsystem NVMe Qualified Name |
| 811 |
|
| 812 |
``int version`` |
| 813 |
Key version to use |
| 814 |
|
| 815 |
``int hmac`` |
| 816 |
HMAC algorithm |
| 817 |
|
| 818 |
``unsigned char *configured_key`` |
| 819 |
Configured key data to derive the key from |
| 820 |
|
| 821 |
``int key_len`` |
| 822 |
Length of **configured_key** |
| 823 |
|
| 824 |
**Description** |
| 825 |
|
| 826 |
Derives a 'retained' TLS key as specified in NVMe TCP and |
| 827 |
generate the corresponding TLs identity. This version differs |
| 828 |
from **nvme_generate_tls_key_identity\(\)** in that it uses the original |
| 829 |
implementation for HKDF-Expand-Label which does not prefix the 'info' |
| 830 |
and 'label' string with the length. |
| 831 |
|
| 832 |
**Return** |
| 833 |
|
| 834 |
The string containing the TLS identity. It is the responsibility |
| 835 |
of the caller to free the returned string. |
| 836 |
|
| 837 |
|
| 838 |
.. c:function:: long nvme_revoke_tls_key (const char *keyring, const char *key_type, const char *identity) |
| 839 |
|
| 840 |
Revoke TLS key from keyring |
| 841 |
|
| 842 |
**Parameters** |
| 843 |
|
| 844 |
``const char *keyring`` |
| 845 |
Keyring to use |
| 846 |
|
| 847 |
``const char *key_type`` |
| 848 |
Type of the key to revoke |
| 849 |
|
| 850 |
``const char *identity`` |
| 851 |
Key identity string |
| 852 |
|
| 853 |
**Return** |
| 854 |
|
| 855 |
0 on success or on failure -1 with errno set. |
| 856 |
|
| 857 |
|
| 858 |
.. c:function:: char * nvme_export_tls_key (const unsigned char *key_data, int key_len) |
| 859 |
|
| 860 |
Export a TLS key |
| 861 |
|
| 862 |
**Parameters** |
| 863 |
|
| 864 |
``const unsigned char *key_data`` |
| 865 |
Raw data of the key |
| 866 |
|
| 867 |
``int key_len`` |
| 868 |
Length of **key_data** |
| 869 |
|
| 870 |
**Description** |
| 871 |
|
| 872 |
Returns **key_data** in the PSK Interchange format as defined in section |
| 873 |
3.6.1.5 of the NVMe TCP Transport specification. |
| 874 |
|
| 875 |
**Return** |
| 876 |
|
| 877 |
The string containing the TLS identity or NULL with errno set |
| 878 |
on error. It is the responsibility of the caller to free the returned |
| 879 |
string. |
| 880 |
|
| 881 |
|
| 882 |
.. c:function:: char * nvme_export_tls_key_versioned (unsigned char version, unsigned char hmac, const unsigned char *key_data, size_t key_len) |
| 883 |
|
| 884 |
Export a TLS pre-shared key |
| 885 |
|
| 886 |
**Parameters** |
| 887 |
|
| 888 |
``unsigned char version`` |
| 889 |
Indicated the representation of the TLS PSK |
| 890 |
|
| 891 |
``unsigned char hmac`` |
| 892 |
HMAC algorithm used to transfor the configured PSK |
| 893 |
in a retained PSK |
| 894 |
|
| 895 |
``const unsigned char *key_data`` |
| 896 |
Raw data of the key |
| 897 |
|
| 898 |
``size_t key_len`` |
| 899 |
Length of **key_data** |
| 900 |
|
| 901 |
**Description** |
| 902 |
|
| 903 |
Returns **key_data** in the PSK Interchange format as defined in section |
| 904 |
3.6.1.5 of the NVMe TCP Transport specification. |
| 905 |
|
| 906 |
**Return** |
| 907 |
|
| 908 |
The string containing the TLS identity or NULL with errno set |
| 909 |
on error. It is the responsibility of the caller to free the returned |
| 910 |
string. |
| 911 |
|
| 912 |
|
| 913 |
.. c:function:: unsigned char * nvme_import_tls_key (const char *encoded_key, int *key_len, unsigned int *hmac) |
| 914 |
|
| 915 |
Import a TLS key |
| 916 |
|
| 917 |
**Parameters** |
| 918 |
|
| 919 |
``const char *encoded_key`` |
| 920 |
TLS key in PSK interchange format |
| 921 |
|
| 922 |
``int *key_len`` |
| 923 |
Length of the resulting key data |
| 924 |
|
| 925 |
``unsigned int *hmac`` |
| 926 |
HMAC algorithm |
| 927 |
|
| 928 |
**Description** |
| 929 |
|
| 930 |
Imports **key_data** in the PSK Interchange format as defined in section |
| 931 |
3.6.1.5 of the NVMe TCP Transport specification. |
| 932 |
|
| 933 |
**Return** |
| 934 |
|
| 935 |
The raw data of the PSK or NULL with errno set on error. It is |
| 936 |
the responsibility of the caller to free the returned string. |
| 937 |
|
| 938 |
|
| 939 |
.. c:function:: unsigned char * nvme_import_tls_key_versioned (const char *encoded_key, unsigned char *version, unsigned char *hmac, size_t *key_len) |
| 940 |
|
| 941 |
Import a TLS key |
| 942 |
|
| 943 |
**Parameters** |
| 944 |
|
| 945 |
``const char *encoded_key`` |
| 946 |
TLS key in PSK interchange format |
| 947 |
|
| 948 |
``unsigned char *version`` |
| 949 |
Indicated the representation of the TLS PSK |
| 950 |
|
| 951 |
``unsigned char *hmac`` |
| 952 |
HMAC algorithm used to transfor the configured |
| 953 |
PSK in a retained PSK |
| 954 |
|
| 955 |
``size_t *key_len`` |
| 956 |
Length of the resulting key data |
| 957 |
|
| 958 |
**Description** |
| 959 |
|
| 960 |
Imports **key_data** in the PSK Interchange format as defined in section |
| 961 |
3.6.1.5 of the NVMe TCP Transport specification. |
| 962 |
|
| 963 |
**Return** |
| 964 |
|
| 965 |
The raw data of the PSK or NULL with errno set on error. It is |
| 966 |
the responsibility of the caller to free the returned string. |
| 967 |
|
| 968 |
|
| 969 |
.. c:function:: int nvme_submit_passthru (int fd, unsigned long ioctl_cmd, struct nvme_passthru_cmd *cmd, __u32 *result) |
| 970 |
|
| 971 |
Low level ioctl wrapper for passthru commands |
| 972 |
|
| 973 |
**Parameters** |
| 974 |
|
| 975 |
``int fd`` |
| 976 |
File descriptor of the nvme device |
| 977 |
|
| 978 |
``unsigned long ioctl_cmd`` |
| 979 |
IOCTL command id |
| 980 |
|
| 981 |
``struct nvme_passthru_cmd *cmd`` |
| 982 |
Passhtru command |
| 983 |
|
| 984 |
``__u32 *result`` |
| 985 |
Optional field to return the result |
| 986 |
|
| 987 |
**Description** |
| 988 |
|
| 989 |
This is a low level library function which should not be used directly. It is |
| 990 |
exposed as weak symbol so that the user application is able to provide their own |
| 991 |
implementation of this function with additional debugging or logging code. |
| 992 |
|
| 993 |
**Return** |
| 994 |
|
| 995 |
The value from the ioctl system call (see ioctl documentation) |
| 996 |
|
| 997 |
|
| 998 |
.. c:function:: int nvme_submit_passthru64 (int fd, unsigned long ioctl_cmd, struct nvme_passthru_cmd64 *cmd, __u64 *result) |
| 999 |
|
| 1000 |
Low level ioctl wrapper for passthru commands |
| 1001 |
|
| 1002 |
**Parameters** |
| 1003 |
|
| 1004 |
``int fd`` |
| 1005 |
File descriptor of the nvme device |
| 1006 |
|
| 1007 |
``unsigned long ioctl_cmd`` |
| 1008 |
IOCTL command id |
| 1009 |
|
| 1010 |
``struct nvme_passthru_cmd64 *cmd`` |
| 1011 |
Passhtru command |
| 1012 |
|
| 1013 |
``__u64 *result`` |
| 1014 |
Optional field to return the result |
| 1015 |
|
| 1016 |
**Description** |
| 1017 |
|
| 1018 |
This is a low level library function which should not be used directly. It is |
| 1019 |
exposed as weak symbol so that the user application is able to provide their own |
| 1020 |
implementation of this function with additional debugging or logging code. |
| 1021 |
|
| 1022 |
**Return** |
| 1023 |
|
| 1024 |
The value from the ioctl system call (see ioctl documentation) |
| 1025 |
|
| 1026 |
|