blob: 627eaccaf66f48ef0a0394269d7e20d6262e0fbe [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "translation_map.h"
31
32#include "wlct_os.h"
33
34translation_map::translation_map ()
35{
36 //nothing to do
37}
38
39translation_map::~translation_map ()
40{
41 //nothing to do
42}
43
44bool translation_map::add_to_translation_map (const char* key, const char* address, const char* start, const char* end)
45{
46 u_int32_t int_address;
47 int int_start, int_end;
48 char *end_ptr;
49
50 int_address = (u_int32_t)strtoul(address, &end_ptr, 0);
51 if (0 != *end_ptr) {
52 ERR("Error converting %s to int\n", address);
53 EXIT (-1);
54 }
55
56 int_start = strtoul(start, &end_ptr, 0);
57 if (0 != *end_ptr) {
58 ERR("Error converting %s to int\n", start);
59 EXIT (-1);
60 }
61
62 int_end = strtoul(end, &end_ptr, 0);
63 if (0 != *end_ptr) {
64 ERR("Error converting %s to int\n", end);
65 EXIT (-1);
66 }
67
68 return add_to_translation_map(key, int_address, int_start, int_end);
69}
70
71
72bool translation_map::add_to_translation_map (const char* key, const u_int32_t address, const int start, const int end)
73{
74 full_address_t temp_address = {address, start, end};
75 string temp_string (key);
76 translation_map_t::value_type entry (key, temp_address);
77 pair <translation_map_t::iterator, bool> ret;
78 ret = m_map.insert(entry);
79 return (ret.second);
80}
81
82bool translation_map::get_from_translation_map (const char* key, u_int32_t *address, int *start, int *end) const
83{
84 translation_map_t::const_iterator iter;
85 string temp_string (key);
86 iter = m_map.find(temp_string);
87 if ( iter == m_map.end( ) )
88 {
89 return false;
90 } else {
91 *address = iter->second.address;
92 *start = iter->second.start;
93 *end = iter->second.end;
94 return true;
95 }
96}
97