aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/misc.c
blob: f10b9d30f3293f99f49b9d3afd914fc3146c36b8 (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
/*
 * This file is part of libsamsung-ipc.
 *
 * Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
 * Copyright (C) 2014 Paul Kocialkowski <contact@paulk.fr>
 *
 * libsamsung-ipc 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.
 *
 * libsamsung-ipc 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 libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.
 */

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

#include <samsung-ipc.h>

int ipc_misc_me_version_setup(struct ipc_misc_me_version_request_data *data)
{
    if (data == NULL)
        return -1;

    memset(data, 0, sizeof(struct ipc_misc_me_version_request_data));
    data->magic = 0xff;

    return 0;
}

char *ipc_misc_me_imsi_imsi_extract(const void *data, size_t size)
{
    struct ipc_misc_me_imsi_header *header;
    char *imsi;
    size_t imsi_length;

    if (data == NULL || size < sizeof(struct ipc_misc_me_imsi_header))
        return NULL;

    header = (struct ipc_misc_me_imsi_header *) data;

    // header->length doesn't count the final null character
    imsi_length = header->length + sizeof(char);

    imsi = (char *) calloc(1, imsi_length);

    strncpy(imsi, (char *) data + sizeof(struct ipc_misc_me_imsi_header), header->length);
    imsi[header->length] = '\0';

    return imsi;
}

char *ipc_misc_me_sn_extract(const struct ipc_misc_me_sn_response_data *data)
{
    char *string;
    size_t length;

    if (data == NULL || data->length > sizeof(data->data))
        return NULL;

    length = data->length + sizeof(char);

    string = (char *) calloc(1, length);

    strncpy(string, (char *) &data->data, data->length);
    string[data->length] = '\0';

    return string;
}

// vim:ts=4:sw=4:expandtab