+#ifdef SEAMLESS_TEST
+ unsigned char test_tone[8] = {0x2a, 0x24, 0xb4, 0x24, 0x2a, 0x25, 0xb5, 0x25};
+ p = buff + MISDN_HEADER_LEN;
+ for (i = 0; i < len; i++)
+ *p++ = test_tone[(bchannel->test + i) & 7];
+ bchannel->test = (bchannel->test + len) & 7;
+#endif
+ if (bchannel->nodsp_queue) {
+ space = (bchannel->nodsp_queue_out - bchannel->nodsp_queue_in - 1) & (QUEUE_BUFFER_SIZE - 1);
+ if (len > space) {
+ CERROR(bchannel->call, NULL, "Queue buffer overflow, space is %d, len is %d.\n", space, len);
+ return;
+ }
+ p = buff + MISDN_HEADER_LEN;
+ in = bchannel->nodsp_queue_in;
+ for (i = 0; i < len; i++) {
+ bchannel->nodsp_queue_buffer[in] = *p++;
+ in = (in + 1) & (QUEUE_BUFFER_SIZE - 1);
+ }
+ bchannel->nodsp_queue_in = in;
+ if (bchannel->queue_sent == 0) /* if there is no pending data */
+ bchannel_send_queue(bchannel);
+ return;
+ }
+ ret = sendto(bchannel->b_sock, buff, MISDN_HEADER_LEN+len, 0, NULL, 0);
+ if (ret < 0)
+ CERROR(bchannel->call, NULL, "Failed to send to socket %d\n", bchannel->b_sock);
+}
+
+
+/*
+ * in case of a send queue, we send from that queue rather directly
+ */
+static void bchannel_send_queue(struct bchannel *bchannel)
+{
+ unsigned char buff[1024 + MISDN_HEADER_LEN], *p = buff + MISDN_HEADER_LEN;
+ struct mISDNhead *frm = (struct mISDNhead *)buff;
+ int ret;
+ int i;
+ int len, out;
+
+ len = (bchannel->nodsp_queue_in - bchannel->nodsp_queue_out) & (QUEUE_BUFFER_SIZE - 1);
+ if (len == 0)
+ return; /* mISDN driver received all load */
+#if 0
+ printf("%4d:(%s|%s)\n", bchannel->nodsp_queue_out,
+ "----------------------------------------------------------------"+64-len/(8192/64),
+ " "+len/(8192/64));
+#endif
+ if (len > 1024)
+ len = 1024;
+ frm->prim = PH_DATA_REQ;
+ frm->id = 0;
+ out = bchannel->nodsp_queue_out;
+ for (i = 0; i < len; i++) {
+ *p++ = bchannel->nodsp_queue_buffer[out];
+ out = (out + 1) & (QUEUE_BUFFER_SIZE - 1);
+ }
+ bchannel->nodsp_queue_out = out;