uint8_t *g_netbuf_put_data(GNetBuf *msg, uint8_t *data, unsigned int len) { uint8_t *tmp; /* Make room for more data */ tmp = g_netbuf_put(msg, len); /* Copy body data to object */ memcpy(tmp, data, len); return tmp; }
/* * Function obex_insert_connectframe () * * Add the data needed to send/reply to a connect * */ int obex_insert_connectframe(obex_t *self, obex_object_t *object) { obex_connect_hdr_t *conn_hdr; DEBUG(4, "\n"); object->tx_nonhdr_data = g_netbuf_new(4); if(!object->tx_nonhdr_data) return -1; conn_hdr = (obex_connect_hdr_t *) object->tx_nonhdr_data->data; conn_hdr->version = OBEX_VERSION; conn_hdr->flags = 0x00; /* Flags */ conn_hdr->mtu = htons(self->mtu_rx); /* Max packet size */ g_netbuf_put(object->tx_nonhdr_data, 4); return 0; }
/* * Function obex_data_indication (self) * * Read/Feed some input from device and find out which packet it is * */ int obex_data_indication(obex_t *self, uint8_t *buf, int buflen) { obex_common_hdr_t *hdr; GNetBuf *msg; int final; int actual = 0; unsigned int size; int ret; DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); msg = self->rx_msg; /* First we need 3 bytes to be able to know how much data to read */ if(msg->len < 3) { actual = obex_transport_read(self, 3 - (msg->len), buf, buflen); DEBUG(4, "Got %d bytes\n", actual); /* Check if we are still connected */ if (actual <= 0) { obex_deliver_event(self, OBEX_EV_LINKERR, 0, 0, TRUE); return actual; } buf += actual; buflen -= actual; g_netbuf_put(msg, actual); } /* If we have 3 bytes data we can decide how big the packet is */ if(msg->len >= 3) { hdr = (obex_common_hdr_t *) msg->data; size = ntohs(hdr->len); actual = 0; if(msg->len != (int) ntohs(hdr->len)) { actual = obex_transport_read(self, size - msg->len, buf, buflen); /* Check if we are still connected */ if (actual <= 0) { obex_deliver_event(self, OBEX_EV_LINKERR, 0, 0, TRUE); return actual; } } } else { /* Wait until we have at least 3 bytes data */ DEBUG(3, "Need at least 3 bytes got only %d!\n", msg->len); return actual; } /* New data has been inserted at the end of message */ g_netbuf_put(msg, actual); DEBUG(1, "Got %d bytes msg len=%d\n", actual, msg->len); /* * Make sure that the buffer we have, actually has the specified * number of bytes. If not the frame may have been fragmented, and * we will then need to read more from the socket. */ /* Make sure we have a whole packet */ if (size > msg->len) { DEBUG(3, "Need more data, size=%d, len=%d!\n", size, msg->len); /* I'll be back! */ return msg->len; } DUMPBUFFER(2, "Rx", msg); actual = msg->len; final = hdr->opcode & OBEX_FINAL; /* Extract final bit */