bridging: Ensure successful T.38 negotation
[asterisk/asterisk.git] / bridges / bridge_simple.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2007, Digium, Inc.
5  *
6  * Joshua Colp <jcolp@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Simple two channel bridging module
22  *
23  * \author Joshua Colp <jcolp@digium.com>
24  *
25  * \ingroup bridges
26  */
27
28 /*** MODULEINFO
29         <support_level>core</support_level>
30  ***/
31
32 #include "asterisk.h"
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39
40 #include "asterisk/module.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/bridge.h"
43 #include "asterisk/bridge_technology.h"
44 #include "asterisk/frame.h"
45
46 static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
47 {
48         struct ast_channel *c0 = AST_LIST_FIRST(&bridge->channels)->chan;
49         struct ast_channel *c1 = AST_LIST_LAST(&bridge->channels)->chan;
50
51         /*
52          * If this is the first channel we can't make it compatible...
53          * unless we make it compatible with itself.  O.o
54          */
55         if (c0 == c1) {
56                 return 0;
57         }
58
59         /* Request resend of T.38 negotiation if in progress and the other leg not yet T.38
60          */
61         if (ast_channel_get_t38_state(c0) == T38_STATE_NEGOTIATING && ast_channel_get_t38_state(c1) == T38_STATE_UNKNOWN) {
62                 struct ast_control_t38_parameters parameters = { .request_response = AST_T38_REQUEST_PARMS, };
63                 ast_debug(3, "Sending T.38 param renegotiation to first channel %s.\n", ast_channel_name(c0));
64                 ast_indicate_data(c0, AST_CONTROL_T38_PARAMETERS, &parameters, sizeof(parameters));
65         }
66         if (ast_channel_get_t38_state(c1) == T38_STATE_NEGOTIATING && ast_channel_get_t38_state(c0) == T38_STATE_UNKNOWN) {
67                 struct ast_control_t38_parameters parameters = { .request_response = AST_T38_REQUEST_PARMS, };
68                 ast_debug(3, "Sending T.38 param renegotiation to second channel %s.\n", ast_channel_name(c1));
69                 ast_indicate_data(c1, AST_CONTROL_T38_PARAMETERS, &parameters, sizeof(parameters));
70         }
71
72         return ast_channel_make_compatible(c0, c1);
73 }
74
75 static int simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
76 {
77         return ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
78 }
79
80 static struct ast_bridge_technology simple_bridge = {
81         .name = "simple_bridge",
82         .capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX,
83         .preference = AST_BRIDGE_PREFERENCE_BASE_1TO1MIX,
84         .join = simple_bridge_join,
85         .write = simple_bridge_write,
86 };
87
88 static int unload_module(void)
89 {
90         ast_bridge_technology_unregister(&simple_bridge);
91         return 0;
92 }
93
94 static int load_module(void)
95 {
96         if (ast_bridge_technology_register(&simple_bridge)) {
97                 unload_module();
98                 return AST_MODULE_LOAD_DECLINE;
99         }
100         return AST_MODULE_LOAD_SUCCESS;
101 }
102
103 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple two channel bridging module");