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
114
115
|
/* libgsmd voice call support
*
* (C) 2006-2007 by OpenMoko, Inc.
* Written by Harald Welte <laforge@openmoko.org>
* All Rights Reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libgsmd/voicecall.h>
#include "lgsm_internals.h"
int lgsm_send_simple(struct lgsm_handle *lh, int type, int sub_type)
{
struct gsmd_msg_hdr *gmh;
int rc;
gmh = lgsm_gmh_fill(type, sub_type, 0);
if (!gmh)
return -ENOMEM;
rc = lgsm_send(lh, gmh);
if (rc < gmh->len + sizeof(*gmh)) {
lgsm_gmh_free(gmh);
return -EIO;
}
lgsm_gmh_free(gmh);
return 0;
}
int lgsm_voice_out_init(struct lgsm_handle *lh,
const struct lgsm_addr *number)
{
struct gsmd_msg_hdr *gmh;
struct gsmd_addr *ga;
int rc;
gmh = lgsm_gmh_fill(GSMD_MSG_VOICECALL,
GSMD_VOICECALL_DIAL, sizeof(*ga));
if (!gmh)
return -ENOMEM;
ga = (struct gsmd_addr *) gmh->data;
ga->type = number->type; /* FIXME: is this correct? */
memcpy(ga->number, number->addr, sizeof(ga->number));
ga->number[sizeof(ga->number)-1] = '\0';
rc = lgsm_send(lh, gmh);
if (rc < gmh->len + sizeof(*gmh)) {
lgsm_gmh_free(gmh);
return -EIO;
}
lgsm_gmh_free(gmh);
return 0;
}
int lgsm_voice_dtmf(struct lgsm_handle *lh, char dtmf_char)
{
struct gsmd_msg_hdr *gmh;
struct gsmd_dtmf *gd;
int rc;
gmh = lgsm_gmh_fill(GSMD_MSG_VOICECALL,
GSMD_VOICECALL_DTMF, sizeof(*gd)+1);
if (!gmh)
return -ENOMEM;
gd = (struct gsmd_dtmf *) gmh->data;
gd->len = 1;
gd->dtmf[0] = dtmf_char;
rc = lgsm_send(lh, gmh);
if (rc < gmh->len + sizeof(*gd)+1) {
lgsm_gmh_free(gmh);;
return -EIO;
}
lgsm_gmh_free(gmh);
return 0;
}
int lgsm_voice_in_accept(struct lgsm_handle *lh)
{
return lgsm_send_simple(lh, GSMD_MSG_VOICECALL, GSMD_VOICECALL_ANSWER);
}
int lgsm_voice_hangup(struct lgsm_handle *lh)
{
return lgsm_send_simple(lh, GSMD_MSG_VOICECALL, GSMD_VOICECALL_HANGUP);
}
int lgsm_voice_volume_set(struct lgsm_handle *lh, int volume)
{
/* FIXME: we need to pass along the parameter */
return lgsm_send_simple(lh, GSMD_MSG_VOICECALL, GSMD_VOICECALL_VOL_SET);
}
|