blob: 30e8b8efb46dbd9f60d414fa127cb0228e37ec20 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*
* Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
*
* 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.
*
*/
#ifndef __WIFI_SCAN_PLUGIN_H__
#define __WIFI_SCAN_PLUGIN_H__
#include <log.h>
#include <ua-plugin.h>
#include <net_connection.h>
#include <stdint.h>
#include <sys/socket.h>
#include <netinet/ether.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/if_packet.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAC_ADD_LENGTH 6 /**< MAC address bytes size */
#define IP_ADD_LENGTH 4 /**< IPv4 size */
#define MAX_SIZE_ERROR_BUFFER 256 /**< Error buffer size */
#define MAX_SIZE_BUFFER 128 /**< Max. buffer size */
#define SEND_MAC_TIMER 10 /**< Timer value until sending ARP request */
#define ARP_MAC_TIMER 5 /**< Timer value until receiving ARP response */
#define BROADCAST_MAC_ADDR "ff:ff:ff:ff:ff:ff" /**< Broadcast adress */
#define MAX_MAC_ARP_COUNT 1 /**< Max. count of ARP request */
#define ARP_PACKET_SIZE 60 /**< MAX ARP payload size */
union uchar_to_uint {
unsigned int uint; /**< IP addess for interger */
unsigned char uchar[IP_ADD_LENGTH]; /**< IP address for human */
};
struct arp_message {
/* Ethernet header */
unsigned char h_dest[MAC_ADD_LENGTH]; /**< destination ether addr */
unsigned char h_source[MAC_ADD_LENGTH]; /**< source ether addr */
uint16_t h_proto; /**< packet type ID field */
/* ARP packet */
uint16_t hw_type;/**< hardware type(ARPHRD_ETHER) */
uint16_t p_type;/**< protocol type(ETH_P_IP) */
uint8_t hw_len;/**< hardware address length */
uint8_t p_len; /**< protocol address length */
uint16_t operation;/**< ARP opcode */
uint8_t s_hwaddr[MAC_ADD_LENGTH]; /**< sender hardware address */
uint8_t s_IPaddr[IP_ADD_LENGTH]; /**< sender IP address */
uint8_t t_hwaddr[MAC_ADD_LENGTH]; /**< target hardware address */
uint8_t t_IPaddr[IP_ADD_LENGTH]; /**< target IP address */
uint8_t pad[18]; /**< pad for min. Ethernet payload (60 bytes) */
};
struct arping_data {
struct arp_message arp; /**< ARP structure */
struct sockaddr_ll addr; /**< Socket address structure */
GIOChannel *arp_sock_io; /**< GIO channel */
int arp_id; /**< Raw socket descriptor ID */
int arp_data_id; /**< GIO ID to recieve ARP response */
int is_arp_init; /**< Create ARP packet done */
char arp_source_ip[MAX_SIZE_BUFFER]; /**< Source IP address */
char arp_source_mac[MAX_SIZE_BUFFER]; /**< Source MAC address */
char arp_target_mac[MAX_SIZE_BUFFER]; /**< Target MAC address */
guint arp_send_packet_timer; /**< Timer ID until sending ARP request */
unsigned int arp_send_ip_addr; /**< Sender's IP address (int type) */
unsigned int arp_mac_count; /**< How many received ARP response from the target dev. */
gboolean mobile_detection; /**< Whether receiving ARP resp. from the target device */
};
int __initialize_arp_data(void);
int __start_wifi_detection(const char *ip, const char *mac);
int __start_arp(const char *ip, const char *mac);
int __init_ip_mac_count(void);
int __start_wifi_add_device(const char *ip, const char *mac);
bool __is_device_exists(char *device_id);
void __deinit_arp_data(void);
#ifdef __cplusplus
}
#endif
#endif /* __WIFI_SCAN_PLUGIN_H__*/
|