about summary refs log tree commit diff stats
path: root/tools/datapacker/CMakeLists.txt
blob: 1ef04e2ef25ef4492d3fdf07604209db308b193f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
find_package(Protobuf REQUIRED)

add_executable(datapacker
  main.cpp
  container.cpp
)
set_property(TARGET datapacker PROPERTY CXX_STANDARD 20)
set_property(TARGET datapacker PROPERTY CXX_STANDARD_REQUIRED ON)
target_include_directories(datapacker PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/tools)
target_link_libraries(datapacker PUBLIC protos util protobuf::libprotobuf)
.nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* Copyright 2021 The libwifi Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "../../core/frame/management/beacon.h"
#include "../../core/frame/frame.h"
#include "../../core/frame/tag.h"
#include "../../core/frame/tag_iterator.h"
#include "../../core/misc/types.h"
#include "../../parse/misc/security.h"
#include "beacon.h"
#include "common.h"

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * libwifi_parse_beacon will parse useful fields out of a supplied beacon frame
 * in the format of a struct libwifi_frame.
 *
 * ┌─────────────────────────────────────────────┐
 * │        Header (Ordered or Unordered)        │  ── Beacon Header
 * ├─────────────────────────────────────────────┤
 * │               Fixed Parameters              │  ─┐
 * ├─────────────────────────────────────────────┤   ├── Beacon Body
 * │              Tagged  Parameters             │  ─┘
 * └─────────────────────────────────────────────┘
 */
int libwifi_parse_beacon(struct libwifi_bss *bss, struct libwifi_frame *frame) {
    memset(bss, 0, sizeof(struct libwifi_bss));

    if (frame->frame_control.type != TYPE_MANAGEMENT || frame->frame_control.subtype != SUBTYPE_BEACON) {
        return -EINVAL;
    }

    if (frame->frame_control.flags.ordered) {
        memcpy(bss->receiver, frame->header.mgmt_ordered.addr1, 6);
        memcpy(bss->transmitter, frame->header.mgmt_ordered.addr2, 6);
        memcpy(bss->bssid, frame->header.mgmt_ordered.addr3, 6);
    } else {
        memcpy(bss->receiver, frame->header.mgmt_unordered.addr1, 6);
        memcpy(bss->transmitter, frame->header.mgmt_unordered.addr2, 6);
        memcpy(bss->bssid, frame->header.mgmt_unordered.addr3, 6);
    }

    // Fixed Parameters must be present
    if (frame->len <= (frame->header_len + sizeof(struct libwifi_beacon_fixed_parameters))) {
        return -EINVAL;
    }

    // At least one Tagged Parameter must be present
    if (frame->len < (frame->header_len + sizeof(struct libwifi_beacon_fixed_parameters) + 2)) {
        return -EINVAL;
    }

    struct libwifi_beacon_fixed_parameters *fixed_params =
        (struct libwifi_beacon_fixed_parameters *) frame->body;
    if (libwifi_check_capabilities(fixed_params->capabilities_information, CAPABILITIES_PRIVACY)) {
        bss->encryption_info |= WEP;
    }

    bss->tags.length = (frame->len - (frame->header_len + sizeof(struct libwifi_beacon_fixed_parameters)));
    const unsigned char *tagged_params = frame->body + sizeof(struct libwifi_beacon_fixed_parameters);
    bss->tags.parameters = malloc(bss->tags.length);
    memcpy(bss->tags.parameters, tagged_params, bss->tags.length);

    // Iterate through common BSS tagged parameters (WPA, RSN, etc)
    struct libwifi_tag_iterator it;
    memset(&it, 0, sizeof(struct libwifi_tag_iterator));
    if (libwifi_tag_iterator_init(&it, bss->tags.parameters, bss->tags.length) != 0) {
        return -EINVAL;
    }
    if (libwifi_bss_tag_parser(bss, &it) != 0) {
        return -EINVAL;
    };

    return 0;
}