/* Called whenever we recive a DATA packet */ static int cb_data_ind(struct pdp_t *lib, void *packet, unsigned int len) { struct bssgp_paging_info pinfo; struct sgsn_pdp_ctx *pdp; struct sgsn_mm_ctx *mm; struct msgb *msg; uint8_t *ud; int rc; DEBUGP(DGPRS, "GTP DATA IND from GGSN, length=%u\n", len); pdp = lib->priv; if (!pdp) { DEBUGP(DGPRS, "GTP DATA IND from GGSN for unknown PDP\n"); return -EIO; } mm = pdp->mm; msg = msgb_alloc_headroom(len+256, 128, "GTP->SNDCP"); ud = msgb_put(msg, len); memcpy(ud, packet, len); msgb_tlli(msg) = mm->tlli; msgb_bvci(msg) = mm->bvci; msgb_nsei(msg) = mm->nsei; switch (mm->mm_state) { case GMM_REGISTERED_SUSPENDED: /* initiate PS PAGING procedure */ memset(&pinfo, 0, sizeof(pinfo)); pinfo.mode = BSSGP_PAGING_PS; pinfo.scope = BSSGP_PAGING_BVCI; pinfo.bvci = mm->bvci; pinfo.imsi = mm->imsi; pinfo.ptmsi = &mm->p_tmsi; pinfo.drx_params = mm->drx_parms; pinfo.qos[0] = 0; // FIXME rc = gprs_bssgp_tx_paging(mm->nsei, 0, &pinfo); rate_ctr_inc(&mm->ctrg->ctr[GMM_CTR_PAGING_PS]); /* FIXME: queue the packet we received from GTP */ break; case GMM_REGISTERED_NORMAL: break; default: LOGP(DGPRS, LOGL_ERROR, "GTP DATA IND for TLLI %08X in state " "%u\n", mm->tlli, mm->mm_state); msgb_free(msg); return -1; } rate_ctr_inc(&pdp->ctrg->ctr[PDP_CTR_PKTS_UDATA_OUT]); rate_ctr_add(&pdp->ctrg->ctr[PDP_CTR_BYTES_UDATA_OUT], len); rate_ctr_inc(&mm->ctrg->ctr[GMM_CTR_PKTS_UDATA_OUT]); rate_ctr_add(&mm->ctrg->ctr[GMM_CTR_BYTES_UDATA_OUT], len); return sndcp_unitdata_req(msg, &mm->llme->lle[pdp->sapi], pdp->nsapi, mm); }
static struct msgb *create_auep2() { struct msgb *msg; msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); int len = sprintf((char *)msg->data, "AUEP 18983213 ds/e1-2/[email protected] MGCP 1.0\r\n"); msg->l2h = msgb_put(msg, len); return msg; }
/* allocate a msgb containing a Litecell15_Prim_t */ struct msgb *sysp_msgb_alloc(void) { struct msgb *msg = msgb_alloc(sizeof(Litecell15_Prim_t), "sys_prim"); if (msg) msg->l1h = msgb_put(msg, sizeof(Litecell15_Prim_t)); return msg; }
/* allocate a msgb containing a GsmL1_Prim_t */ struct msgb *l1p_msgb_alloc(void) { struct msgb *msg = msgb_alloc(sizeof(GsmL1_Prim_t), "l1_prim"); if (msg) msg->l1h = msgb_put(msg, sizeof(GsmL1_Prim_t)); return msg; }
static struct msgb *create_msg(const char *str) { struct msgb *msg; msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); int len = sprintf((char *)msg->data, str); msg->l2h = msgb_put(msg, len); return msg; }
/** * @brief Transmit L1CTL_RESET_IND or L1CTL_RESET_CONF to layer 23. * * -- reset indication / confirm -- * * @param [in] msg_type L1CTL primitive message type. * @param [in] reset_type reset type (full, boot or just scheduler reset). */ void l1ctl_tx_reset(struct l1_model_ms *ms, uint8_t msg_type, uint8_t reset_type) { struct msgb *msg = l1ctl_msgb_alloc(msg_type); struct l1ctl_reset *reset_resp = (struct l1ctl_reset *) msgb_put(msg, sizeof(*reset_resp)); reset_resp->type = reset_type; LOGPMS(DL1C, LOGL_INFO, ms, "Tx %s (reset_type: %u)\n", getL1ctlPrimName(msg_type), reset_type); l1ctl_sap_tx_to_l23_inst(ms, msg); }
static int rsl_rll_error(uint8_t cause, struct lapdm_msg_ctx *mctx) { struct msgb *msg; LOGP(DLLAPD, LOGL_NOTICE, "sending MDL-ERROR-IND %d\n", cause); msg = rsl_rll_simple(RSL_MT_ERROR_IND, mctx->chan_nr, mctx->link_id, 1); msg->l2h = msgb_put(msg, sizeof(struct abis_rsl_rll_hdr)); msgb_tlv_put(msg, RSL_IE_RLM_CAUSE, 1, &cause); return rslms_sendmsg(msg, mctx->dl->entity); }
static int forward_ussd(struct sccp_connections *con, const struct ussd_request *req, struct msgb *input) { struct msgb *msg, *copy; struct ipac_msgt_sccp_state *state; struct bsc_nat_ussd_con *ussd; if (!con->bsc->nat->ussd_con) return -1; msg = msgb_alloc_headroom(4096, 128, "forward ussd"); if (!msg) { LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n"); return -1; } copy = msgb_alloc_headroom(4096, 128, "forward bts"); if (!copy) { LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n"); msgb_free(msg); return -1; } copy->l2h = msgb_put(copy, msgb_l2len(input)); memcpy(copy->l2h, input->l2h, msgb_l2len(input)); msg->l2h = msgb_put(msg, 1); msg->l2h[0] = IPAC_MSGT_SCCP_OLD; /* fill out the data */ state = (struct ipac_msgt_sccp_state *) msgb_put(msg, sizeof(*state)); state->trans_id = req->transaction_id; state->invoke_id = req->invoke_id; memcpy(&state->src_ref, &con->remote_ref, sizeof(con->remote_ref)); memcpy(&state->dst_ref, &con->real_ref, sizeof(con->real_ref)); memcpy(state->imsi, con->imsi, strlen(con->imsi)); ussd = con->bsc->nat->ussd_con; bsc_do_write(&ussd->queue, msg, IPAC_PROTO_IPACCESS); bsc_do_write(&ussd->queue, copy, IPAC_PROTO_SCCP); return 0; }
static void quirk_l16tv_put(struct msgb *msg, uint16_t len, uint8_t tag, const uint8_t *val) { uint8_t *buf = msgb_put(msg, len + 2 + 1); *buf++ = (len + 1) >> 8; *buf++ = (len + 1) & 0xff; *buf++ = tag; memcpy(buf, val, len); }
static void start_rach(void) { struct gsm48_sysinfo *s = &sysinfo; uint8_t chan_req_val, chan_req_mask; struct msgb *nmsg; struct abis_rsl_cchan_hdr *ncch; if (rach_count == RACH_MAX) { log_sysinfo(); start_sync(); return; } state = SCAN_STATE_RACH; if (s->neci) { chan_req_mask = 0x0f; chan_req_val = 0x01; LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x " "(OTHER with NECI)\n", chan_req_val); } else { chan_req_mask = 0x1f; chan_req_val = 0xe0; LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (OTHER no NECI)\n", chan_req_val); } rach_ref.valid = 0; rach_ref.cr = random(); rach_ref.cr &= chan_req_mask; rach_ref.cr |= chan_req_val; nmsg = msgb_alloc_headroom(RSL_ALLOC_SIZE+RSL_ALLOC_HEADROOM, RSL_ALLOC_HEADROOM, "GSM 04.06 RSL"); if (!nmsg) return; nmsg->l2h = nmsg->data; ncch = (struct abis_rsl_cchan_hdr *) msgb_put(nmsg, sizeof(*ncch) + 4 + 2 + 2); rsl_init_cchan_hdr(ncch, RSL_MT_CHAN_RQD); ncch->chan_nr = RSL_CHAN_RACH; ncch->data[0] = RSL_IE_REQ_REFERENCE; ncch->data[1] = rach_ref.cr; ncch->data[2] = (s->ccch_conf == 1) << 7; ncch->data[3] = 0; ncch->data[4] = RSL_IE_ACCESS_DELAY; ncch->data[5] = 0; /* no delay */ ncch->data[6] = RSL_IE_MS_POWER; ncch->data[7] = 0; /* full power */ start_timer(RACH_WAIT); lapdm_rslms_recvmsg(nmsg, &ms->lapdm_channel); }
/** * @brief Transmit L1CTL_CCCH_MODE_CONF to layer 23. * * -- common control channel mode confirm -- * * @param [in] ccch_mode the new configured ccch mode. Combined or non-combined, see l1ctl_proto. * * Called by layer 1 to inform layer 2 that the ccch mode was successfully changed. */ void l1ctl_tx_ccch_mode_conf(struct l1_model_ms *ms, uint8_t ccch_mode) { struct msgb *msg = l1ctl_msgb_alloc(L1CTL_CCCH_MODE_CONF); struct l1ctl_ccch_mode_conf *mode_conf; mode_conf = (struct l1ctl_ccch_mode_conf *) msgb_put(msg, sizeof(*mode_conf)); mode_conf->ccch_mode = ccch_mode; LOGPMS(DL1C, LOGL_INFO, ms, "Tx L1CTL_CCCH_MODE_CONF (mode: %u)\n", ccch_mode); l1ctl_sap_tx_to_l23_inst(ms, msg); }
static void l1ctl_tx_tbf_cfg_conf(struct l1_model_ms *ms, const struct l1ctl_tbf_cfg_req *in) { struct msgb *msg = l1ctl_msgb_alloc(L1CTL_TBF_CFG_CONF); struct l1ctl_tbf_cfg_req *out; /* copy over the data from the request */ out = (struct l1ctl_tbf_cfg_req *) msgb_put(msg, sizeof(*out)); *out = *in; l1ctl_sap_tx_to_l23_inst(ms, msg); }
/* send location updating request * (as part of RSLms EST IND / LAPDm SABME) */ static int gsm48_tx_loc_upd_req(struct osmocom_ms *ms, uint8_t chan_nr) { struct msgb *msg = msgb_alloc_headroom(256, 16, "loc_upd_req"); struct gsm48_hdr *gh; struct gsm48_loc_upd_req *lu_r; DEBUGP(DMM, "chan_nr=%u\n", chan_nr); msg->l3h = msgb_put(msg, sizeof(*gh)); gh = (struct gsm48_hdr *) msg->l3h; gh->proto_discr = GSM48_PDISC_MM; gh->msg_type = GSM48_MT_MM_LOC_UPD_REQUEST; lu_r = (struct gsm48_loc_upd_req *) msgb_put(msg, sizeof(*lu_r)); lu_r->type = GSM48_LUPD_IMSI_ATT; lu_r->key_seq = 0; /* FIXME: set LAI and CM1 */ /* FIXME: set MI */ lu_r->mi_len = 0; return rslms_tx_rll_req_l3(ms, RSL_MT_EST_REQ, chan_nr, 0, msg); }
int main(void) { struct tcp_client *c; struct tcp_conf conf = { .ipproto = AF_INET, .port = 1234, .client = { .inet_addr = { inet_addr("127.0.0.1") }, }, }; struct nft_sync_hdr *hdr; struct msg_buff *msgb; char buf[1024]; fd_set fds; msgb = msgb_alloc(NFTS_MAX_REQUEST); if (msgb == NULL) { perror("msgb_alloc"); exit(EXIT_FAILURE); } hdr = msgb_put(msgb, sizeof(struct nft_sync_hdr) + strlen("fetch")); hdr->len = htonl(sizeof(struct nft_sync_hdr) + strlen("fetch")); memcpy(hdr->data, "fetch", strlen("fetch")); c = tcp_client_create(&conf); if (c == NULL) { fprintf(stderr, "cannot initialize TCP client\n"); exit(EXIT_FAILURE); } FD_ZERO(&fds); FD_SET(tcp_client_get_fd(c), &fds); /* Wait for connection ... */ select(tcp_client_get_fd(c) + 1, NULL, &fds, NULL, NULL); if (tcp_client_send(c, msgb_data(msgb), msgb_len(msgb)) < 0) { perror("cannot send to socket"); exit(EXIT_FAILURE); } FD_ZERO(&fds); FD_SET(tcp_client_get_fd(c), &fds); /* Wait to receive data after sending request ... */ select(tcp_client_get_fd(c) + 1, &fds, NULL, NULL, NULL); if (tcp_client_recv(c, buf, sizeof(buf)) < 0) { perror("cannot send to socket"); exit(EXIT_FAILURE); } printf("[TEST OK] Received: %s\n", buf + sizeof(struct nft_sync_hdr)); tcp_client_destroy(c); }
/* * send voice */ int gsm_send_voice(struct osmocom_ms *ms, struct gsm_data_frame *data) { struct msgb *nmsg; nmsg = msgb_alloc_headroom(33 + 64, 64, "TCH/F"); if (!nmsg) return -ENOMEM; nmsg->l2h = msgb_put(nmsg, 33); memcpy(nmsg->l2h, data->data, 33); return gsm48_rr_tx_voice(ms, nmsg); }
/** * @brief Allocates a msgb with set l1ctl header and room for a l3 header and puts l1ctl_info_dl to the msgb data. * * @param [in] msg_type L1CTL primitive message type set to l1ctl_hdr. * @param [in] fn framenumber put into l1ctl_info_dl. * @param [in] snr time slot number put into l1ctl_info_dl. * @param [in] arfcn arfcn put into l1ctl_info_dl. * @return the allocated message. * * The message looks as follows: * # headers * [l1ctl_hdr] : initialized. msgb->l1h points here * [spare-bytes] : L3_MSG_HEAD bytes reserved for l3 header * # data * [l1ctl_info_dl] : initialized with params. msgb->data points here. * [spare-bytes] : L3_MSG_DATA bytes reserved for data. msgb->tail points here. */ struct msgb *l1ctl_create_l2_msg(int msg_type, uint32_t fn, uint16_t snr, uint16_t arfcn) { struct l1ctl_info_dl *dl; struct msgb *msg = l1ctl_msgb_alloc(msg_type); dl = (struct l1ctl_info_dl *) msgb_put(msg, sizeof(*dl)); dl->frame_nr = htonl(fn); dl->snr = htons(snr); dl->band_arfcn = htons(arfcn); return msg; }
static int hsl_bts_connect(struct ipa_client_conn *link) { struct msgb *msg; uint8_t *serno; char serno_buf[16]; struct hsl_unit *unit = link->line->ops->cfg.ipa.dev; struct e1inp_sign_link *sign_link; /* send the minimal message to identify this BTS. */ msg = ipa_msg_alloc(0); if (!msg) return -ENOMEM; *msgb_put(msg, 1) = 0x80; *msgb_put(msg, 1) = 0x80; *msgb_put(msg, 1) = unit->swversion; snprintf(serno_buf, sizeof(serno_buf), "%"PRIx64, unit->serno); serno = msgb_put(msg, strlen(serno_buf)+1); memcpy(serno, serno_buf, strlen(serno_buf)); ipa_msg_push_header(msg, 0); send(link->ofd->fd, msg->data, msg->len, 0); msgb_free(msg); /* ... and enable the signalling link. */ if (!link->line->ops->sign_link_up) { LOGP(DLINP, LOGL_ERROR, "Unable to set signal link, closing socket.\n"); ipa_client_conn_close(link); return -EINVAL; } sign_link = link->line->ops->sign_link_up(&unit, link->line, E1INP_SIGN_NONE); if (sign_link == NULL) { LOGP(DLINP, LOGL_ERROR, "Unable to set signal link, closing socket.\n"); ipa_client_conn_close(link); return -EINVAL; } return 0; }
/** * @brief Transmit L1CTL_TCH_MODE_CONF to layer 23. * * -- traffic channel mode confirm -- * * @param [in] tch_mode the new configured traffic channel mode, see gsm48_chan_mode in gsm_04_08.h. * @param [in] audio_mode the new configured audio mode(s), see l1ctl_tch_mode_req in l1ctl_proto.h. * * Called by layer 1 to inform layer 23 that the traffic channel mode was successfully changed. */ void l1ctl_tx_tch_mode_conf(struct l1_model_ms *ms, uint8_t tch_mode, uint8_t audio_mode) { struct msgb *msg = l1ctl_msgb_alloc(L1CTL_TCH_MODE_CONF); struct l1ctl_tch_mode_conf *mode_conf; mode_conf = (struct l1ctl_tch_mode_conf *) msgb_put(msg, sizeof(*mode_conf)); mode_conf->tch_mode = tch_mode; mode_conf->audio_mode = audio_mode; LOGPMS(DL1C, LOGL_INFO, ms, "Tx L1CTL_TCH_MODE_CONF (tch_mode: %u, audio_mode: %u)\n", tch_mode, audio_mode); l1ctl_sap_tx_to_l23_inst(ms, msg); }
int gsm340_tpdu_encode(struct msgb *msg, struct gsm_sms *sms){ uint8_t *smsp; uint8_t da_len; uint8_t da[12]; /* max len referring to GSM 03.40 */ unsigned int old_msg_len = msg->len; smsp = msgb_put(msg, 1); /* first octet with masked bit */ *smsp = GSM340_SMS_SUBMIT_MS2SC; if(sms->validity_period){ *smsp |= (1 << 4); } *smsp |= (sms->ud_hdr_ind << 6); *smsp |= (sms->status_rep_req << 5); *smsp |= (sms->reply_path_req << 7); /* TP-MR */ smsp = msgb_put(msg, 1); *smsp = sms->msg_ref; /* TP-DA */ da_len = gsm340_gen_da(da, sizeof(da), sms->dest_addr); smsp = msgb_put(msg, da_len); memcpy(smsp, da, da_len); /* TP-PID */ smsp = msgb_put(msg, 1); *smsp = sms->protocol_id; /* TP-DCS */ smsp = msgb_put(msg, 1); *smsp = sms->data_coding_scheme; /* TP-VP */ smsp = msgb_put(msg, 1); *smsp = sms->validity_period; /* TP-UDL */ smsp = msgb_put(msg, 1); *smsp = sms->user_data_len; /* TP-UD */ smsp = msgb_put(msg, sms->user_data_len); memcpy(smsp, sms->user_data, sms->user_data_len); return msg->len - old_msg_len; }
/* 11.1.1 */ static struct msgb *_select_file(struct osim_chan_hdl *st, uint8_t p1, uint8_t p2, const uint8_t *data, uint8_t data_len) { struct msgb *msg; uint8_t *dst; msg = osim_new_apdumsg(0x00, 0xA4, p1, p2, data_len, 256); dst = msgb_put(msg, data_len); memcpy(dst, data, data_len); osim_transceive_apdu(st, msg); return msg; }
static int gsm411_tx_cp_error(struct gsm411_smc_inst *inst, uint8_t cause) { struct msgb *nmsg = gsm411_msgb_alloc(); uint8_t *causep; LOGP(DLSMS, LOGL_NOTICE, "TX CP-ERROR, cause %d (%s)\n", cause, get_value_string(gsm411_cp_cause_strs, cause)); causep = msgb_put(nmsg, 1); *causep = cause; return inst->mm_send(inst, GSM411_MMSMS_DATA_REQ, nmsg, GSM411_MT_CP_ERROR); }
/* Append padding (if required) */ static void lapdm_pad_msgb(struct msgb *msg, uint8_t n201) { int pad_len = n201 - msgb_l2len(msg); uint8_t *data; if (pad_len < 0) { LOGP(DLLAPD, LOGL_ERROR, "cannot pad message that is already too big!\n"); return; } data = msgb_put(msg, pad_len); memset(data, 0x2B, pad_len); }
/* Chapter 12.16 */ int octphy_hw_get_clock_sync_stats(struct octphy_hdl *fl1h) { struct msgb *msg = l1p_msgb_alloc(); tOCTVC1_HW_MSG_CLOCK_SYNC_MGR_STATS_CMD *csc; csc = (tOCTVC1_HW_MSG_CLOCK_SYNC_MGR_STATS_CMD *) msgb_put(msg, sizeof(*csc)); l1if_fill_msg_hdr(&csc->Header, msg, fl1h, cOCTVC1_MSG_TYPE_COMMAND, cOCTVC1_HW_MSG_CLOCK_SYNC_MGR_STATS_CID); mOCTVC1_HW_MSG_CLOCK_SYNC_MGR_STATS_CMD_SWAP(csc); return l1if_req_compl(fl1h, msg, get_clock_sync_stats_cb, NULL); }
/* Chapter 12.1 */ int octphy_hw_get_pcb_info(struct octphy_hdl *fl1h) { struct msgb *msg = l1p_msgb_alloc(); tOCTVC1_HW_MSG_PCB_INFO_CMD *pic; pic = (tOCTVC1_HW_MSG_PCB_INFO_CMD *) msgb_put(msg, sizeof(*pic)); l1if_fill_msg_hdr(&pic->Header, msg, fl1h, cOCTVC1_MSG_TYPE_COMMAND, cOCTVC1_HW_MSG_PCB_INFO_CID); mOCTVC1_HW_MSG_PCB_INFO_CMD_SWAP(pic); return l1if_req_compl(fl1h, msg, get_pcb_info_compl_cb, NULL); }
void lapd_rx_cb(struct osmo_dlsap_prim *dp, uint8_t tei, uint8_t sapi, void *rx_cbdata) { struct msgb *msg = dp->oph.msg; switch (dp->oph.primitive) { case PRIM_DL_EST: DEBUGP(DLAPDTEST, "DL_EST: sapi(%d) tei(%d)\n", sapi, tei); break; case PRIM_DL_REL: DEBUGP(DLAPDTEST, "DL_REL: sapi(%d) tei(%d)\n", sapi, tei); break; case PRIM_DL_DATA: case PRIM_DL_UNIT_DATA: if (dp->oph.operation == PRIM_OP_INDICATION) { struct msgb *nmsg; char *ptr; int x; msg->l2h = msg->l3h; DEBUGP(DLAPDTEST, "RX: %s sapi=%d tei=%d\n", osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)), sapi, tei); LOGP(DLAPDTEST, LOGL_DEBUG, "forwarding message\n"); nmsg = msgb_alloc(1024, "LAPD/test"); if (nmsg == NULL) { LOGP(DLAPDTEST, LOGL_ERROR, "cannot alloc msg\n"); return; } ptr = (char *)msgb_put(nmsg, sizeof(int)); x = *((int *)msg->data); memcpy(ptr, &x, sizeof(int)); /* send the message back to client over LAPD */ lapd_transmit(lapd, tei, sapi, msg); return; } break; case PRIM_MDL_ERROR: DEBUGP(DLMI, "MDL_EERROR: cause(%d)\n", dp->u.error_ind.cause); break; default: printf("ERROR: unknown prim\n"); break; } }
static void loader_start_memput(uint8_t length, uint32_t address, void *data) { struct msgb *msg = msgb_alloc(MSGB_MAX, "loader"); msgb_put_u8(msg, LOADER_MEM_WRITE); msgb_put_u8(msg, length); msgb_put_u16(msg, osmo_crc16(0, data, length)); msgb_put_u32(msg, address); memcpy(msgb_put(msg, length), data, length); loader_send_request(msg); msgb_free(msg); osmoload.state = STATE_QUERY_PENDING; osmoload.command = LOADER_MEM_WRITE; }
static int dtap_rcvmsg(struct osmo_bsc_sccp_con *conn, struct msgb *msg, unsigned int length) { struct dtap_header *header; struct msgb *gsm48; uint8_t *data; int rc, dtap_rc; LOGP(DMSC, LOGL_DEBUG, "Rx MSC DTAP: %s\n", osmo_hexdump(msg->l3h, length)); if (!conn->conn) { LOGP(DMSC, LOGL_ERROR, "No subscriber connection available\n"); return -1; } header = (struct dtap_header *) msg->l3h; if (sizeof(*header) >= length) { LOGP(DMSC, LOGL_ERROR, "The DTAP header does not fit. Wanted: %zu got: %u\n", sizeof(*header), length); LOGP(DMSC, LOGL_ERROR, "hex: %s\n", osmo_hexdump(msg->l3h, length)); return -1; } if (header->length > length - sizeof(*header)) { LOGP(DMSC, LOGL_ERROR, "The DTAP l4 information does not fit: header: %u length: %u\n", header->length, length); LOGP(DMSC, LOGL_ERROR, "hex: %s\n", osmo_hexdump(msg->l3h, length)); return -1; } LOGP(DMSC, LOGL_INFO, "Rx MSC DTAP, SAPI: %u CHAN: %u\n", header->link_id & 0x07, header->link_id & 0xC0); /* forward the data */ gsm48 = gsm48_msgb_alloc(); if (!gsm48) { LOGP(DMSC, LOGL_ERROR, "Allocation of the message failed.\n"); return -1; } gsm48->l3h = gsm48->data; data = msgb_put(gsm48, length - sizeof(*header)); memcpy(data, msg->l3h + sizeof(*header), length - sizeof(*header)); /* pass it to the filter for extra actions */ rc = bsc_scan_msc_msg(conn->conn, gsm48); dtap_rc = gsm0808_submit_dtap(conn->conn, gsm48, header->link_id, 1); if (rc == BSS_SEND_USSD) bsc_send_welcome_ussd(conn->conn); return dtap_rc; }
static void tpu_debug(void) { uint16_t *tpu_base = (uint16_t *)BASE_ADDR_TPU_RAM; unsigned int tpu_size = tpu_ptr - tpu_base; struct msgb *msg = sercomm_alloc_msgb(tpu_size*2); uint16_t *data; uint32_t *fn; uint16_t reg; int i; /* prepend tpu memory dump with frame number */ fn = (uint32_t *) msgb_put(msg, sizeof(fn)); *fn = l1s.current_time.fn; tpu_ram_read_en(1); data = (uint16_t *) msgb_put(msg, tpu_size*2); for (i = 0; i < tpu_size; i ++) data[i] = tpu_base[i]; tpu_ram_read_en(0); sercomm_sendmsg(SC_DLCI_DEBUG, msg); }
/* Chapter 12.9 */ int octphy_hw_get_rf_port_info(struct octphy_hdl *fl1h, uint32_t index) { struct msgb *msg = l1p_msgb_alloc(); tOCTVC1_HW_MSG_RF_PORT_INFO_CMD *pic; pic = (tOCTVC1_HW_MSG_RF_PORT_INFO_CMD *) msgb_put(msg, sizeof(*pic)); l1if_fill_msg_hdr(&pic->Header, msg, fl1h, cOCTVC1_MSG_TYPE_COMMAND, cOCTVC1_HW_MSG_RF_PORT_INFO_CID); pic->ulPortIndex = index; mOCTVC1_HW_MSG_RF_PORT_INFO_CMD_SWAP(pic); return l1if_req_compl(fl1h, msg, rf_port_info_compl_cb, NULL); }
/** * @brief Allocates a msgb with set l1ctl header and room for a l3 header. * * @param [in] msg_type L1CTL primitive message type set to l1ctl_hdr. * @return the allocated message. * * The message looks as follows: * # headers * [l1ctl_hdr] : initialized. msgb->l1h points here * [spare-bytes] : L3_MSG_HEAD bytes reserved for l3 header * # data * [spare-bytes] : L3_MSG_DATA bytes reserved for data. msgb->tail points here. msgb->data points here. */ struct msgb *l1ctl_msgb_alloc(uint8_t msg_type) { struct msgb *msg; struct l1ctl_hdr *l1h; msg = msgb_alloc_headroom(L3_MSG_SIZE, L3_MSG_HEAD, "l1ctl"); OSMO_ASSERT(msg); l1h = (struct l1ctl_hdr *) msgb_put(msg, sizeof(*l1h)); l1h->msg_type = msg_type; l1h->flags = 0; msg->l1h = (uint8_t *)l1h; return msg; }