From 84406e2779bf77dd4257df11f9361e5d04e000eb Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 4 Jun 2011 16:42:47 +0200 Subject: sccp: Make sccp_write take an additional local context For connection less data there is no way to pass a per context data for outgoing data, add one. --- include/sccp/sccp.h | 5 +++-- src/sccp.c | 32 +++++++++++++++++--------------- tests/sccp/sccp_test.c | 14 +++++++------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/sccp/sccp.h b/include/sccp/sccp.h index 9e692cf..3c30a73 100644 --- a/include/sccp/sccp.h +++ b/include/sccp/sccp.h @@ -108,7 +108,7 @@ struct sccp_connection { * sccp will call outgoing whenever outgoing data exists * The conn is NULL for UDT and other messages without a connection */ -int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *ctx), void *context); +int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *gctx, void *ctx), void *context); int sccp_system_incoming(struct msgb *data); /** @@ -150,7 +150,8 @@ int sccp_connection_set_incoming(const struct sockaddr_sccp *sock, */ int sccp_write(struct msgb *data, const struct sockaddr_sccp *sock_sender, - const struct sockaddr_sccp *sock_target, int class); + const struct sockaddr_sccp *sock_target, + int class, void *ctx); int sccp_set_read(const struct sockaddr_sccp *sock, int (*read_cb)(struct msgb *msgb, unsigned int, void *user_data), void *user_data); diff --git a/src/sccp.c b/src/sccp.c index 2556e16..e061d37 100644 --- a/src/sccp.c +++ b/src/sccp.c @@ -48,7 +48,8 @@ const struct sockaddr_sccp sccp_ssn_bssap = { struct sccp_system { /* layer3 -> layer2 */ - void (*write_data)(struct sccp_connection *conn, struct msgb *data, void *context); + void (*write_data)(struct sccp_connection *conn, struct msgb *data, + void *gctx, void *ctx); void *write_context; }; @@ -94,9 +95,9 @@ static struct sccp_data_callback *_find_ssn(uint8_t ssn) } -static void _send_msg(struct sccp_connection *conn, struct msgb *msg) +static void _send_msg(struct sccp_connection *conn, struct msgb *msg, void *ctx) { - sccp_system.write_data(conn, msg, sccp_system.write_context); + sccp_system.write_data(conn, msg, sccp_system.write_context, ctx); } /* @@ -561,7 +562,8 @@ struct msgb *sccp_create_udt(int class, const struct sockaddr_sccp *in, } static int _sccp_send_data(int class, const struct sockaddr_sccp *in, - const struct sockaddr_sccp *out, struct msgb *payload) + const struct sockaddr_sccp *out, + struct msgb *payload, void *ctx) { struct msgb *msg; @@ -569,7 +571,7 @@ static int _sccp_send_data(int class, const struct sockaddr_sccp *in, if (!msg) return -1; - _send_msg(NULL, msg); + _send_msg(NULL, msg, ctx); return 0; } @@ -696,7 +698,7 @@ static int _sccp_send_refuse(struct sccp_source_reference *src_ref, int cause) if (!msgb) return -1; - _send_msg(NULL, msgb); + _send_msg(NULL, msgb, NULL); return 0; } @@ -743,7 +745,7 @@ static int _sccp_send_connection_confirm(struct sccp_connection *connection) if (!response) return -1; - _send_msg(connection, response); + _send_msg(connection, response, NULL); _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_ESTABLISHED); return 0; } @@ -804,7 +806,7 @@ static int _sccp_send_connection_request(struct sccp_connection *connection, llist_add_tail(&connection->list, &sccp_connections); _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REQUEST); - _send_msg(connection, request); + _send_msg(connection, request, NULL); return 0; } @@ -852,7 +854,7 @@ static int _sccp_send_connection_data(struct sccp_connection *conn, struct msgb if (!msgb) return -1; - _send_msg(conn, msgb); + _send_msg(conn, msgb, NULL); return 0; } @@ -875,7 +877,7 @@ static int _sccp_send_connection_it(struct sccp_connection *conn) it->sequencing[0] = it->sequencing[1] = 0; it->credit = 0; - _send_msg(conn, msgb); + _send_msg(conn, msgb, NULL); return 0; } @@ -920,7 +922,7 @@ static int _sccp_send_connection_released(struct sccp_connection *conn, int caus return -1; _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_RELEASE); - _send_msg(conn, msg); + _send_msg(conn, msg, NULL); return 0; } @@ -1080,7 +1082,7 @@ static int _sccp_send_connection_release_complete(struct sccp_connection *connec memcpy(&rlc->source_local_reference, &connection->source_local_reference, sizeof(struct sccp_source_reference)); - _send_msg(connection, msgb); + _send_msg(connection, msgb, NULL); /* * Remove from the list of active connections and set the state. User code @@ -1201,7 +1203,7 @@ found: } -int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *ctx), void *ctx) +int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *, void *), void *ctx) { sccp_system.write_data = outgoing; sccp_system.write_context = ctx; @@ -1344,9 +1346,9 @@ int sccp_connection_set_incoming(const struct sockaddr_sccp *sock, } int sccp_write(struct msgb *data, const struct sockaddr_sccp *in, - const struct sockaddr_sccp *out, int class) + const struct sockaddr_sccp *out, int class, void *ctx) { - return _sccp_send_data(class, in, out, data); + return _sccp_send_data(class, in, out, data, ctx); } int sccp_set_read(const struct sockaddr_sccp *sock, diff --git a/tests/sccp/sccp_test.c b/tests/sccp/sccp_test.c index 4705c6d..b4c2f14 100644 --- a/tests/sccp/sccp_test.c +++ b/tests/sccp/sccp_test.c @@ -391,7 +391,7 @@ static int write_called = 0; /* * writing these packets and expecting a result */ -int sccp_read_cb(struct msgb *data, unsigned len, void *context) +int sccp_read_cb(struct msgb *data, unsigned len, void *gctx) { uint16_t payload_length = test_data[current_test].payload_length; const uint8_t *got, *wanted; @@ -427,7 +427,7 @@ int sccp_read_cb(struct msgb *data, unsigned len, void *context) return 0; } -void sccp_write_cb(struct sccp_connection *conn, struct msgb *data, void *ctx) +void sccp_write_cb(struct sccp_connection *conn, struct msgb *data, void *gctx, void *ctx) { int i = 0; const uint8_t *got, *wanted; @@ -479,7 +479,7 @@ int sccp_accept_cb(struct sccp_connection *connection, void *user_data) return 0; } -static void sccp_udt_write_cb(struct sccp_connection *conn, struct msgb *data, void *context) +static void sccp_udt_write_cb(struct sccp_connection *conn, struct msgb *data, void *gtx, void *ctx) { const uint8_t *got, *wanted; int i; @@ -544,7 +544,7 @@ static void test_sccp_send_udt(void) matched = write_called = 0; printf("Testing packet: %d\n", current_test); - sccp_write(msg, &sccp_ssn_bssap, &sccp_ssn_bssap, 0); + sccp_write(msg, &sccp_ssn_bssap, &sccp_ssn_bssap, 0, NULL); if (!matched || !write_called) FAIL("current test: %d matched: %d write: %d\n", @@ -556,7 +556,7 @@ static void test_sccp_send_udt(void) /* send udt from one end to another */ static unsigned int test_value = 0x2442; -static int sccp_udt_read(struct msgb *data, unsigned int len, void *context) +static int sccp_udt_read(struct msgb *data, unsigned int len, void *gctx) { unsigned int *val; @@ -570,7 +570,7 @@ static int sccp_udt_read(struct msgb *data, unsigned int len, void *context) return 0; } -static void sccp_write_loop(struct sccp_connection *conn, struct msgb *data, void *context) +static void sccp_write_loop(struct sccp_connection *conn, struct msgb *data, void *gctx, void *ctx) { /* send it back to us */ sccp_system_incoming(data); @@ -593,7 +593,7 @@ static void test_sccp_udt_communication(void) *val = test_value; matched = 0; - sccp_write(data, &sccp_ssn_bssap, &sccp_ssn_bssap, 0); + sccp_write(data, &sccp_ssn_bssap, &sccp_ssn_bssap, 0, NULL); if (!matched) FAIL("Talking with us didn't work\n"); -- cgit v1.2.3