コード例 #1
0
ファイル: packet.c プロジェクト: Nymphetaminer/dsl-n55u
int
send_join_response(int fd, LaneControl_t *lc, int lecid, 
		   unsigned int status)
{
  Debug_unit(&conn_unit,"Send_join_response called to %d",fd);
  lc->opcode = htons(LE_JOIN_RESPONSE);
  lc->status = (unsigned short)htons(0xffff & status);
  lc->lecid = lecid;

  if (send_control_frame(fd, lc) == 0) {
    dump_error(&conn_unit,"Send join response failed");
    return 0;
  }
  return 1;
}
コード例 #2
0
ファイル: connect.c プロジェクト: earthGavinLee/hg556a_source
static int
forward_flush_response(Conn_t *conn)
{
  int a;

  Debug_unit(&conn_unit, "Forward_flush_response called");
  dump_conn(conn);
  for (conn = connlist; conn; conn=conn->next) {
    if (conn->sfd) {
      a = send_control_frame(conn->sfd, control_packet);
      if (a == 0)
	dump_error(&conn_unit, "Forward flush response failed");
    }
  } 
  return 1;
}
コード例 #3
0
ファイル: connect.c プロジェクト: earthGavinLee/hg556a_source
static int
topology_request(Conn_t *conn)
{
  int a;

  Debug_unit(&conn_unit, "Topology request called");
  dump_conn(conn);

  for(conn=connlist;conn;conn=conn->next) {
    if (conn->sfd) {
      a = send_control_frame(conn->sfd, control_packet);
      if (a == 0)
	dump_error(&conn_unit, "Topology request send failed");
    }
  }
  return 1;
}
コード例 #4
0
ファイル: packet.c プロジェクト: Nymphetaminer/dsl-n55u
int
send_register_response(int fd, LaneControl_t *lc,
		       unsigned int status, int reg)
{

  Debug_unit(&conn_unit,"Send_register_response called to %d",fd);
  if (reg == 1)
    lc->opcode = htons(LE_REGISTER_RESPONSE);
  else
    lc->opcode = htons(LE_UNREGISTER_RESPONSE);
  lc->status = (unsigned short)htons(0xffff & status);

  if (send_control_frame(fd, lc) == 0) {
    dump_error(&conn_unit,"Send register response failed");
    return 0;
  }
  return 1;
}
コード例 #5
0
ファイル: connect.c プロジェクト: earthGavinLee/hg556a_source
static int
arp_forward_response(Conn_t *conn)
{
  int a;
  Conn_t *tmp;

  Debug_unit(&conn_unit,"Arp forward response called");
  dump_conn(conn);
  /* We got response. Forward it to all */

  for (tmp = connlist;tmp;tmp=tmp->next) {
    if (tmp->sfd) {
      a = send_control_frame(tmp->sfd, control_packet);
      if (a == 0)
	dump_error(&conn_unit, "Forward arp response write failed");
    }
  }
  return 1;
}
コード例 #6
0
ファイル: packet.c プロジェクト: Nymphetaminer/dsl-n55u
int
send_arp_response(int fd, LaneControl_t *lc,
		  unsigned int status, Reg_t *found)
{
  
  Debug_unit(&conn_unit,"Send_arp_response called to %d",fd);

  lc->opcode = htons(LE_ARP_RESPONSE);
  lc->status = (unsigned short)htons((0xffff & status));

  /* Clear the potential Remote flag */
  if ((lc->flags & htons(LE_FLAG_REMOTE)) == htons(LE_FLAG_REMOTE)) {
    lc->flags = (lc->flags ^ htons(LE_FLAG_REMOTE));
  }
  if (found) {
    memcpy(&lc->target_addr,&found->atm_address, sizeof(lc->target_addr));
  }
  if (send_control_frame(fd, lc) == 0) {
    dump_error(&conn_unit,"Send arp response failed");
    return 0;
  }
  return 1;
}
コード例 #7
0
ファイル: websocket.c プロジェクト: moderepo/WICED-SDK
static void process_frames(wiced_tcp_socket_t *sock, websocket_msg_handler_t binary_msg_handler, websocket_msg_handler_t text_msg_handler, void *ctx) {
    wiced_result_t ret;
    char *buf, *cur;
    uint32_t len;
    websocket_frame_t frame;
    websocket_message_t msg;
    wiced_bool_t exit_loop = WICED_FALSE;

    message_init(&msg);

    while (WICED_TRUE) {
        buf = NULL;
        ret = receive_data(sock, 3000, &buf, &len);

        if (ret == WICED_TIMEOUT) {
            continue;
        }

        if (ret != WICED_SUCCESS) {
            WPRINT_LIB_INFO( ("(WebSocket) Failed to read from socket (err=%u)\n", ret) );
            break;
        }

        WPRINT_LIB_DEBUG( ("(WebSocket) Received %u bytes\n", (unsigned int)len) );

        cur = buf;
        while (len > 0) {
            if (get_frame(&cur, &len, &frame) != WICED_SUCCESS) {
                WPRINT_LIB_INFO( ("(WebSocket) Failed to read frame (err=%u)\n", ret) );
                exit_loop = WICED_TRUE;
                break;
            }

            if (frame.opcode == WS_OPCODE_PING) {
                WPRINT_LIB_DEBUG( ("(WebSocket) Received PING frame.\n"));
                send_control_frame(sock, WS_OPCODE_PONG, frame.payload, frame.payload_len);
            }
            else if (frame.opcode == WS_OPCODE_PONG) {
                WPRINT_LIB_DEBUG( ("(WebSocket) Received PONG frame.\n"));
                /* Nothing to do. */
            }
            else if (frame.opcode == WS_OPCODE_CLOSE) {
                WPRINT_LIB_DEBUG( ("(WebSocket) Received CLOSE frame.\n") );
                /* Echo the CLOSE frame with the 2-byte status code. */
                if (frame.payload_len >= 2) {
                    send_control_frame(sock, WS_OPCODE_CLOSE, frame.payload, 2);
                }
                else {
                    send_control_frame(sock, WS_OPCODE_CLOSE, NULL, 0);
                }
                exit_loop = WICED_TRUE;
                break;
            }
            else if (frame.opcode == WS_OPCODE_CONTINUATION) {
                WPRINT_LIB_DEBUG( ("(WebSocket) Received CONTINUATION frame.\n") );

                if (msg.is_active) {
                    message_append(&msg, frame.payload, frame.payload_len);

                    if (frame.is_final) {
                        consume_message(&msg, binary_msg_handler, text_msg_handler, ctx);
                    }
                }
                else {
                    exit_loop = WICED_TRUE;
                    break;
                }
            }
            else if (frame.opcode == WS_OPCODE_TEXT) {
                WPRINT_LIB_DEBUG( ("(WebSocket) Received TEXT frame.\n") );

                if (msg.is_active) {
                    WPRINT_LIB_DEBUG( ("(WebSocket) A pending message already exists.\n") );
                    exit_loop = WICED_TRUE;
                    break;
                }

                message_start(&msg, WICED_TRUE, frame.payload, frame.payload_len);

                if (frame.is_final) {
                    consume_message(&msg, binary_msg_handler, text_msg_handler, ctx);
                }
            }
            else if (frame.opcode == WS_OPCODE_BINARY) {
                WPRINT_LIB_DEBUG( ("(WebSocket) Received BINARY frame.\n") );

                if (msg.is_active) {
                    WPRINT_LIB_DEBUG( ("(WebSocket) A pending message already exists.\n") );
                    exit_loop = WICED_TRUE;
                    break;
                }

                message_start(&msg, WICED_FALSE, frame.payload, frame.payload_len);

                if (frame.is_final) {
                    consume_message(&msg, binary_msg_handler, text_msg_handler, ctx);
                }
            }
            else {
                WPRINT_LIB_INFO(("(WebSocket) Received invalid opcode %02X\n", frame.opcode));
                exit_loop = WICED_TRUE;
                break;
            }
        }

        free(buf);

        if (exit_loop) {
            WPRINT_LIB_INFO( ("(WebSocket) Exiting read loop.\n") );
            break;
        }
    }

    message_deinit(&msg);
}