File: speech.cc

package info (click to toggle)
kismet 2008-05-R1-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,232 kB
  • ctags: 3,998
  • sloc: cpp: 33,568; sh: 5,544; ansic: 459; makefile: 457; perl: 62; sql: 41
file content (113 lines) | stat: -rw-r--r-- 3,911 bytes parent folder | download | duplicates (4)
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
106
107
108
109
110
111
112
113
/*
    This file is part of Kismet

    Kismet is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Kismet is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Kismet; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "config.h"

#include <ctype.h>

#include "speech.h"

char speech_alphabet[2][36][12]={
    {"owl pha", "Bravo", "Charlie", "Deltah", "Echo", "Foxtrot", "Golf",
    "Hotel", "India", "Juliet", "Keylo", "line-ah", "Mike", "November",
    "Oscar", "Pawpa", "qwa-bec", "Romeo", "Sierra", "Tango", "you-niform",
    "vickk-tour", "Whiskey", "ecks-ray", "Yankee", "Zulu",
    "0", "1", "2", "3", "4", "5", "6", "7", "8", "niner"},
    {"ae", "BEE", "SEE", "DEE", "EAE", "EF", "GEE", "H", "EYE", "JAY", "KAY",
    "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
};

string EncodeSpeechString(string in_str, int in_encoding) {
    if (in_encoding != SPEECH_ENCODING_NATO && in_encoding != SPEECH_ENCODING_SPELL)
        return in_str;

    string encodestr;
    for (unsigned int x = 0; x < in_str.length(); x++) {
        char chr = toupper(in_str[x]);
        int pos;

        // Find our encoding in the array
        if (chr >= '0' && chr <= '9')
            pos = 26 + (chr - '0');
        else if (chr >= 'A' && chr <= 'Z')
            pos = chr - 'A';
        else
            continue;

        if (in_encoding == SPEECH_ENCODING_NATO) {
            encodestr += speech_alphabet[0][pos];
        } else if (in_encoding == SPEECH_ENCODING_SPELL) {
            encodestr += speech_alphabet[1][pos];
        }

        encodestr += "., ";
    }

    return encodestr;
}

string IntExpandSpeech(string in_str, int in_encoding, string in_ssid, mac_addr in_mac,
                       int in_channel, float in_maxrate) {
    string strtemplate = in_str;

    for (unsigned int nl = strtemplate.find("%"); nl < strtemplate.length();
         nl = strtemplate.find("%", nl+1))
    {
        char op = strtemplate[nl+1];
        strtemplate.erase(nl, 2);

        if (op == 'b') {
            strtemplate.insert(nl, EncodeSpeechString(in_mac.Mac2String(), in_encoding));
        } else if (op == 's') {
            if (in_ssid == NOSSID)
                strtemplate.insert(nl, EncodeSpeechString("unknown name", in_encoding));
            else
                strtemplate.insert(nl, EncodeSpeechString(in_ssid, in_encoding));
        } else if (op == 'c') {
            char chan[3];
            snprintf(chan, 3, "%d", in_channel);
            strtemplate.insert(nl, chan);
        } else if (op == 'r') {
            char maxrate[5];
            snprintf(maxrate, 5, "%2.1f", in_maxrate);
            strtemplate.insert(nl, maxrate);
        }
    }

    return strtemplate;
}

string ExpandSpeechString(string in_str, const packet_info *in_info, int in_encoding) {
    string strtemplate;

    strtemplate = IntExpandSpeech(in_str, in_encoding, in_info->ssid, in_info->bssid_mac,
                                  in_info->channel, in_info->maxrate);

    return strtemplate;
}

string ExpandSpeechString(string in_str, const wireless_network *in_info, int in_encoding) {
    string strtemplate;

    strtemplate = IntExpandSpeech(in_str, in_encoding, in_info->ssid, in_info->bssid,
                                  in_info->channel, in_info->maxrate);

    return strtemplate;
}