http_deamon.c
2.83 KB
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
/**
* \file http_deamon.c
* \author Zeufack Arnel - Member of an LO53 group-project (Other Members: TONY DUONG - YVON MBOUGUEM - JOEL WABO)
* \date 15 Juin 2016
* \brief This file contains the function for the management of the requests sended by the map server.
*
* \details In this file, we catch the request made by the http server, we extract the informations (mobile device mac address)
* then we calculage the average signal strenght of the device based on the rssi samples captured
*/
#include "http_deamon.h"
#include "pcap-thread.h"
Element * tracked_devices;
int answer_to_connection (void *cls, struct MHD_Connection *connection,
const char *url, const char *method,
const char *version, const char *upload_data,
size_t *upload_data_size, void **con_cls)
{
struct MHD_Response *response;
int ret;
const u_char *mobile_mac = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "mobile_mac");
char * interface = "wlan0";
u_char * Ap_mac = malloc(sizeof(u_char)*18);
u_char * avg_rssi_value = malloc(sizeof(u_char)*8);
u_char * number_of_samples = malloc(sizeof(u_char)*8);
u_char * token = malloc(18*sizeof(u_char));
for(ret=0; ret<17; ret++)
token[ret] = mobile_mac[ret];
token[17] = '\0';
/*
u_char * token = malloc(18*sizeof(u_char));
for(ret=1; ret<18; ret++)
token[ret-1] = mobile_mac[ret];
token[17] = '\0';
*/
get_ap_mac(&Ap_mac,interface);
printf("Ap mac : #%s#\n", Ap_mac);
//usleep(2500000);
calculate_avg(&tracked_devices, token, number_of_samples, avg_rssi_value);
u_char * page = malloc(sizeof(u_char)*170);
strcpy(page,"{\n\"infosignal\": [{");
strcat(page,"\n\""); strcat(page,"mobile_mac"); strcat(page,"\""); strcat(page,":");
strcat(page,"\""); strcat(page,mobile_mac); strcat(page,"\""); strcat(page,",\n");
strcat(page,"\""); strcat(page,"ap_mac"); strcat(page,"\""); strcat(page,":");
strcat(page,"\""); strcat(page,Ap_mac); strcat(page,"\""); strcat(page,",\n");
strcat(page,"\""); strcat(page,"number_of_samples"); strcat(page,"\""); strcat(page,":");
strcat(page,"\""); strcat(page,number_of_samples); strcat(page,"\""); strcat(page,",\n");
strcat(page,"\""); strcat(page,"avg_rssi_value"); strcat(page,"\""); strcat(page,":");
strcat(page,"\""); strcat(page,avg_rssi_value); strcat(page,"\"");
strcat(page,"\n}\n]}\0");
printf("%s\n",page);
u_char * pagee = malloc(strlen(page)*sizeof(u_char));
strcpy(pagee,page);
response =
MHD_create_response_from_buffer (strlen(pagee), (void *)pagee,
MHD_RESPMEM_MUST_COPY);
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
//free(page);
//free(pagee);
free(Ap_mac);
free(avg_rssi_value);
free(number_of_samples);
free(token);
return ret;
}