|
4 | 4 |
|
5 | 5 | #include "rx_st20p_app.h"
|
6 | 6 |
|
| 7 | +#include <intel-ipsec-mb.h> |
| 8 | + |
| 9 | +static IMB_MGR* mgr; |
| 10 | + |
| 11 | +static uint8_t cipher_key[16] = {0}; |
| 12 | +static uint8_t cipher_iv[16] = {0}; |
| 13 | +DECLARE_ALIGNED(static uint32_t exp_enc_key[4 * 15], 16); |
| 14 | +DECLARE_ALIGNED(static uint32_t exp_dec_key[4 * 15], 16); |
| 15 | +static IMB_JOB* job; |
| 16 | + |
7 | 17 | static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session* s,
|
8 | 18 | struct st_frame* frame) {
|
9 | 19 | struct st_display* d = s->display;
|
10 | 20 | int idx = s->idx;
|
11 | 21 |
|
12 | 22 | if (s->st20p_destination_file) {
|
13 |
| - if (!fwrite(frame->addr[0], 1, s->st20p_frame_size, s->st20p_destination_file)) { |
| 23 | + job = IMB_GET_NEXT_JOB(mgr); |
| 24 | + job->src = frame->addr[0]; |
| 25 | + job->dst = s->tmp_framebuff; |
| 26 | + job->cipher_mode = IMB_CIPHER_CNTR; |
| 27 | + job->hash_alg = IMB_AUTH_NULL; |
| 28 | + job->enc_keys = exp_enc_key; |
| 29 | + job->dec_keys = exp_dec_key; |
| 30 | + job->iv = cipher_iv; |
| 31 | + job->cipher_direction = IMB_DIR_DECRYPT; |
| 32 | + job->chain_order = IMB_ORDER_HASH_CIPHER; |
| 33 | + job->key_len_in_bytes = 16; |
| 34 | + job->iv_len_in_bytes = 16; |
| 35 | + job->cipher_start_src_offset_in_bytes = 0; |
| 36 | + job->msg_len_to_cipher_in_bytes = s->st20p_frame_size; |
| 37 | + job = IMB_SUBMIT_JOB(mgr); |
| 38 | + if (job == NULL) { |
| 39 | + const int err = imb_get_errno(mgr); |
| 40 | + printf( |
| 41 | + "%d Unexpected null return from submit job()\n" |
| 42 | + "\t Error code %d, %s\n", |
| 43 | + __LINE__, err, imb_get_strerror(err)); |
| 44 | + exit(1); |
| 45 | + } |
| 46 | + if (job->status != IMB_STATUS_COMPLETED) { |
| 47 | + const int err = imb_get_errno(mgr); |
| 48 | + printf( |
| 49 | + "%d Wrong job status\n" |
| 50 | + "\t Error code %d, %s\n", |
| 51 | + __LINE__, err, imb_get_strerror(err)); |
| 52 | + } |
| 53 | + |
| 54 | + if (!fwrite(s->tmp_framebuff, 1, s->st20p_frame_size, s->st20p_destination_file)) { |
14 | 55 | err("%s(%d), failed to write frame to file %s\n", __func__, idx,
|
15 | 56 | s->st20p_destination_url);
|
16 | 57 | }
|
@@ -57,6 +98,10 @@ static void* app_rx_st20p_frame_thread(void* arg) {
|
57 | 98 | uint8_t shas[SHA256_DIGEST_LENGTH];
|
58 | 99 | int idx = s->idx;
|
59 | 100 |
|
| 101 | + mgr = alloc_mb_mgr(0); |
| 102 | + init_mb_mgr_auto(mgr, NULL); |
| 103 | + IMB_AES_KEYEXP_128(mgr, cipher_key, exp_enc_key, exp_dec_key); |
| 104 | + |
60 | 105 | info("%s(%d), start\n", __func__, s->idx);
|
61 | 106 | while (!s->st20p_app_thread_stop) {
|
62 | 107 | frame = st20p_rx_get_frame(s->handle);
|
@@ -103,6 +148,8 @@ static void* app_rx_st20p_frame_thread(void* arg) {
|
103 | 148 | }
|
104 | 149 | info("%s(%d), stop\n", __func__, s->idx);
|
105 | 150 |
|
| 151 | + free_mb_mgr(mgr); |
| 152 | + |
106 | 153 | return NULL;
|
107 | 154 | }
|
108 | 155 |
|
@@ -286,6 +333,12 @@ static int app_rx_st20p_init(struct st_app_context* ctx,
|
286 | 333 | s->handle = handle;
|
287 | 334 |
|
288 | 335 | s->st20p_frame_size = st20p_rx_frame_size(handle);
|
| 336 | + s->tmp_framebuff = malloc(s->st20p_frame_size); |
| 337 | + if (!s->tmp_framebuff) { |
| 338 | + err("%s(%d), failed to allocate tmp frame buffer\n", __func__, idx); |
| 339 | + app_rx_st20p_uinit(s); |
| 340 | + return -ENOMEM; |
| 341 | + } |
289 | 342 |
|
290 | 343 | ret = app_rx_st20p_init_frame_thread(s);
|
291 | 344 | if (ret < 0) {
|
@@ -374,6 +427,7 @@ int st_app_rx_st20p_sessions_uinit(struct st_app_context* ctx) {
|
374 | 427 | for (i = 0; i < ctx->rx_st20p_session_cnt; i++) {
|
375 | 428 | s = &ctx->rx_st20p_sessions[i];
|
376 | 429 | app_rx_st20p_uinit(s);
|
| 430 | + free(s->tmp_framebuff); |
377 | 431 | }
|
378 | 432 | st_app_free(ctx->rx_st20p_sessions);
|
379 | 433 |
|
|
0 commit comments