Harald Welte | 283c7fd | 2015-12-21 23:35:56 +0100 | [diff] [blame] | 1 | #include "sua_test_common.h" |
| 2 | |
| 3 | static const struct log_info_cat log_cat[] = { |
| 4 | [DMAIN] = { |
| 5 | .name = "DMAIN", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 6 | .color = "", |
| 7 | .description = "Main program", |
| 8 | }, |
| 9 | [DSUA] = { |
| 10 | .name = "DSUA", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 11 | .color = "", |
| 12 | .description = "SCCP User Adaption", |
| 13 | }, |
| 14 | [DXUA] = { |
| 15 | .name = "DXUA", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 16 | .color = "", |
| 17 | .description = "X User Adaption encoding/decoding", |
| 18 | }, |
| 19 | |
| 20 | }; |
| 21 | |
| 22 | const struct log_info test_log_info = { |
| 23 | .cat = log_cat, |
| 24 | .num_cat = ARRAY_SIZE(log_cat), |
| 25 | }; |
| 26 | |
Harald Welte | 8960704 | 2015-12-21 23:51:08 +0100 | [diff] [blame] | 27 | int tx_unitdata(struct osmo_sua_link *link) |
Harald Welte | 283c7fd | 2015-12-21 23:35:56 +0100 | [diff] [blame] | 28 | { |
| 29 | struct msgb *msg = msgb_alloc(1024, "tx_unitdata"); |
| 30 | struct osmo_scu_prim *prim; |
| 31 | struct osmo_scu_unitdata_param *param; |
| 32 | uint8_t *cur; |
| 33 | |
| 34 | prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim)); |
| 35 | param = &prim->u.unitdata; |
| 36 | param->calling_addr.presence = OSMO_SCCP_ADDR_T_SSN; |
| 37 | param->called_addr.presence = OSMO_SCCP_ADDR_T_SSN; |
| 38 | osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_REQUEST, msg); |
| 39 | |
| 40 | cur = msg->l2h = msgb_put(msg, 3); |
| 41 | cur[0] = 1; cur[1] = 2; cur[2] = 3; |
| 42 | |
Harald Welte | 8960704 | 2015-12-21 23:51:08 +0100 | [diff] [blame] | 43 | return osmo_sua_user_link_down(link, &prim->oph); |
Harald Welte | 283c7fd | 2015-12-21 23:35:56 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static void sccp_make_addr_pc_ssn(struct osmo_sccp_addr *addr, uint32_t pc, uint32_t ssn) |
| 47 | { |
| 48 | addr->presence = OSMO_SCCP_ADDR_T_SSN | OSMO_SCCP_ADDR_T_PC; |
| 49 | addr->ssn = ssn; |
| 50 | addr->pc = pc; |
| 51 | } |
| 52 | |
| 53 | #define SSN_RANAP 142 |
| 54 | |
| 55 | struct osmo_prim_hdr *make_conn_req(uint32_t conn_id) |
| 56 | { |
| 57 | struct msgb *msg = msgb_alloc(1024, "conn_req"); |
| 58 | struct osmo_scu_prim *prim; |
| 59 | |
| 60 | prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim)); |
| 61 | osmo_prim_init(&prim->oph, SCCP_SAP_USER, |
| 62 | OSMO_SCU_PRIM_N_CONNECT, |
| 63 | PRIM_OP_REQUEST, msg); |
| 64 | /* Set SSN for calling and called addr */ |
| 65 | sccp_make_addr_pc_ssn(&prim->u.connect.called_addr, 2, SSN_RANAP); |
| 66 | sccp_make_addr_pc_ssn(&prim->u.connect.calling_addr, 1, SSN_RANAP); |
| 67 | prim->u.connect.sccp_class = 2; |
| 68 | prim->u.connect.conn_id = conn_id; |
| 69 | |
| 70 | return &prim->oph; |
| 71 | } |
| 72 | |
Harald Welte | 8960704 | 2015-12-21 23:51:08 +0100 | [diff] [blame] | 73 | int tx_conn_req(struct osmo_sua_link *link, uint32_t conn_id) |
Harald Welte | 283c7fd | 2015-12-21 23:35:56 +0100 | [diff] [blame] | 74 | { |
| 75 | struct osmo_prim_hdr *prim = make_conn_req(conn_id); |
Harald Welte | 8960704 | 2015-12-21 23:51:08 +0100 | [diff] [blame] | 76 | return osmo_sua_user_link_down(link, prim); |
Harald Welte | 283c7fd | 2015-12-21 23:35:56 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | struct osmo_prim_hdr * |
| 80 | make_dt1_req(uint32_t conn_id, const uint8_t *data, unsigned int len) |
| 81 | { |
| 82 | struct msgb *msg = msgb_alloc(1024, "dt1"); |
| 83 | struct osmo_scu_prim *prim; |
| 84 | |
| 85 | prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim)); |
| 86 | osmo_prim_init(&prim->oph, SCCP_SAP_USER, |
| 87 | OSMO_SCU_PRIM_N_DATA, |
| 88 | PRIM_OP_REQUEST, msg); |
| 89 | prim->u.data.conn_id = conn_id; |
| 90 | |
| 91 | msg->l2h = msgb_put(msg, len); |
| 92 | memcpy(msg->l2h, data, len); |
| 93 | |
| 94 | return &prim->oph; |
| 95 | } |