blob: fbfae3cc330f040fb2e89072c4e66e85d7af5f73 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
3 * Copyright (c) 2017 Intel Corporation
4 * Copyright (c) 2019, Infosys Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include <getopt.h>
23
24#include "log.h"
25#include "options.h"
26
27void parse_args(int argc, char **argv)
28{
29 int args_set = 0;
30 int c = 0;
31
32 const struct option long_options[] = {
33 {"config_file", required_argument, NULL, 'f'},
34 {0, 0, 0, 0}
35 };
36
37 do {
38 int option_index = 0;
39
40 c = getopt_long(argc, argv, "f:", long_options,
41 &option_index);
42
43 if (c == -1)
44 break;
45
46 switch (c) {
47 case 'f':
48 break;
49 default:
50 log_msg(LOG_ERROR, "Unknown argument - %s.", argv[optind]);
51 exit(0);
52 }
53 } while (c != -1);
54
55 if ((args_set & REQ_ARGS) != REQ_ARGS) {
56 log_msg(LOG_ERROR, "Usage: %s\n", argv[0]);
57 for (c = 0; long_options[c].name; ++c) {
58 log_msg(LOG_ERROR, "\t[ -%s | -%c ] %s\n",
59 long_options[c].name,
60 long_options[c].val,
61 long_options[c].name);
62 }
63 exit(0);
64 }
65}
66
67void log_buffer_free(char** buffer)
68{
69 if(*buffer != NULL)
70 free(*buffer);
71 *buffer = NULL;
72}
73
74void convert_imsi_to_bcd_str(uint8_t *src, uint8_t* dest)
75{
76 if (!src || !dest)
77 {
78 log_msg(LOG_ERROR, "invalid buffer pointers.\n");
79 return;
80 }
81
82 int len = BINARY_IMSI_LEN;
83 int i = 0;
84 for (; i < len - 1; i++) {
85 dest[2 * i] = '0' + ((src[i] >> 4) & 0x0F);
86 dest[2 * i + 1] = '0' + ((src[i]) & 0x0F);
87 }
88
89 dest[2 * (len-1)] = '0' + ((src[i] >> 4) & 0x0F);
90
91 return;
92}
93
94