<commit_before>/*
  oo-parse - parse osdp messages

  (C)Copyright 2017-2022 Smithee Solutions LLC

  Support provided by the Security Industry Association
  http://www.securityindustry.org

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
    http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/


#include <stdio.h>
#include <memory.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>


#include <osdp-tls.h>
#include <open-osdp.h>
#include <osdp_conformance.h>
#include <iec-xwrite.h>


extern OSDP_CONTEXT context;
extern OSDP_INTEROP_ASSESSMENT osdp_conformance;
extern OSDP_PARAMETERS p_card;
extern OSDP_BUFFER osdp_buf;
unsigned char last_command_received;
unsigned char last_sequence_received;
unsigned char last_check_value;
extern char trace_in_buffer [];


/*
  osdp_parse_message - parses OSDP message

  Note: if verbosity is set (global m_verbosity) it also prints the PDU
  to stderr.
*/
int
  osdp_parse_message
    (OSDP_CONTEXT *context,
    int role,
    OSDP_MSG *m,
    OSDP_HDR *returned_hdr)

{ /* osdp_parse_message */

  int display;
  int hashable_length;
  int i;
  unsigned int msg_lth;
  int msg_check_type;
  int msg_data_length;
  int msg_scb;
  int msg_sqn;
  OSDP_HDR *p;
  unsigned short int parsed_crc;
  int sec_blk_length;
  int sec_block_type;
  int status;
  unsigned wire_cksum;
  unsigned short int wire_crc;


  p = (OSDP_HDR *)m->ptr;

  status = ST_MSG_TOO_SHORT;

  m->data_payload = NULL;
  m->security_block_length = 0; // assume no security block
  msg_data_length = 0;

  msg_check_type = (p->ctrl) & 0x04;
  if (msg_check_type EQUALS 0)
  {
    m->check_size = 1;
// do NOT change m_check global just because this packet was different...    m_check = OSDP_CHECKSUM; // Issue #11
//    if (context->verbosity > 2) fprintf(context->log, "m_check set to CHECKSUM (parse)\n");
  }
  else
  {
    m->check_size = 2;
//    m_check = OSDP_CRC;
  };
  // rememeber the last one in so we answer the same way
  context->last_checksize_in = m->check_size;
fprintf(stderr, "DEBUG: last_checkize_in %d\n", context->last_checksize_in);

  if (m->lth > OSDP_OFFICIAL_MSG_MAX)
    status = ST_MSG_TOO_LONG;<commit_msg>remove debug print<commit_after>/*
  oo-parse - parse osdp messages

  (C)Copyright 2017-2022 Smithee Solutions LLC

  Support provided by the Security Industry Association
  http://www.securityindustry.org

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
    http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/


#include <stdio.h>
#include <memory.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>


#include <osdp-tls.h>
#include <open-osdp.h>
#include <osdp_conformance.h>
#include <iec-xwrite.h>


extern OSDP_CONTEXT context;
extern OSDP_INTEROP_ASSESSMENT osdp_conformance;
extern OSDP_PARAMETERS p_card;
extern OSDP_BUFFER osdp_buf;
unsigned char last_command_received;
unsigned char last_sequence_received;
unsigned char last_check_value;
extern char trace_in_buffer [];


/*
  osdp_parse_message - parses OSDP message

  Note: if verbosity is set (global m_verbosity) it also prints the PDU
  to stderr.
*/
int
  osdp_parse_message
    (OSDP_CONTEXT *context,
    int role,
    OSDP_MSG *m,
    OSDP_HDR *returned_hdr)

{ /* osdp_parse_message */

  int display;
  int hashable_length;
  int i;
  unsigned int msg_lth;
  int msg_check_type;
  int msg_data_length;
  int msg_scb;
  int msg_sqn;
  OSDP_HDR *p;
  unsigned short int parsed_crc;
  int sec_blk_length;
  int sec_block_type;
  int status;
  unsigned wire_cksum;
  unsigned short int wire_crc;


  p = (OSDP_HDR *)m->ptr;

  status = ST_MSG_TOO_SHORT;

  m->data_payload = NULL;
  m->security_block_length = 0; // assume no security block
  msg_data_length = 0;

  msg_check_type = (p->ctrl) & 0x04;
  if (msg_check_type EQUALS 0)
  {
    m->check_size = 1;
// do NOT change m_check global just because this packet was different...    m_check = OSDP_CHECKSUM; // Issue #11
//    if (context->verbosity > 2) fprintf(context->log, "m_check set to CHECKSUM (parse)\n");
  }
  else
  {
    m->check_size = 2;
//    m_check = OSDP_CRC;
  };
  // rememeber the last one in so we answer the same way
  context->last_checksize_in = m->check_size;

  if (m->lth > OSDP_OFFICIAL_MSG_MAX)
    status = ST_MSG_TOO_LONG;
{'fraction_non_alphanumeric': 0.08732943469785576, 'fraction_numerical': 0.008966861598440545, 'mean_word_length': 3.804307116104869, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7347381', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1764, 'n_words': 552}