Exemple #1
0
def test_bytestaffing():
 '''
 Function returns an array of test indexes that failed.
 All bytestaffing tests should pass without errors
 >>> test_bytestaffing()
 []
 '''
 from time import time
 test = load('bytestaffing_test',())
 a = time()
 test_data = [random_data(1000) for i in xrange(100)]
 b = time()
 tests = [ test(data,sizeof(data)) for data in test_data ]
 c = time()
 return [i for i in tests if i]
Exemple #2
0
from interface_basis import load,DumpableStructure,DATE,TIME,ByteArray
from contract import DYNAMIC_A
from events import EVENT_CONTRACT_ADD2,EVENT_CONTRACT
from config import term_full_cost,term_half_cost,hall_id
import purse

from ctypes import c_void_p,c_uint64,c_uint32,c_uint16,c_uint8,sizeof,pointer as p,POINTER as P,cast
from datetime import datetime,timedelta
from calendar import monthrange
from mfex import *

#workaround for wrong ctypes behaviour when writing bit fields
term_set_validity       = load('term_set_validity'         ,(c_void_p,c_uint16,c_uint16))
#initializes time contract based on given parameters (see u2.dll source)
term_init               = load('term_init'                 ,(c_void_p,c_void_p))

FULL_COST = term_full_cost
HALF_COST = term_half_cost
STATIC  = 13
DYNAMIC = 14
KEY = 27
ENC = 0x3

# returns an array of tuples with beforehand crafted information
# about business logic of term contract refill.
# Tuple format: (0) begin day, (1) end day, (2) arguments to refill for this case
# Special case with february is being checked here.
def get_refill_table(date,student):
  #student can refill their cards for a half cost but only for a full month
  base_cost = HALF_COST if student else FULL_COST
Exemple #3
0
 def write(self,blocks = None):
  if blocks: return [self.write_block(block,self.enc) for block in blocks]
  if card_sector_write(self.card.reader,self,self.enc): raise SectorWriteError(self.num)

class ByBlockSector(Sector):
 def read(self,blocks = None):
  if not blocks: blocks = self.blocks
  for b in blocks:
   if card_block_read(self.card.reader,self,b,self.enc[b]): raise SectorReadError(self.num,b)

 def write(self,blocks = None):
  if not blocks: blocks = self.blocks
  for b in blocks:
   if card_block_write(self.card.reader,self,b,self.enc[b]): raise SectorWriteError(self.num,b)

reader_field_on         = load('reader_field_on'           ,(Reader,))
reader_field_off        = load('reader_field_off'          ,(Reader,))

reader_get_sn           = load('reader_get_sn'             ,(Reader,P(ByteArray(8))))
reader_get_version      = load('reader_get_version'        ,(Reader,P(ByteArray(7))))

reader_save             = load('reader_save'               ,(Reader,P(c_char)))
reader_load             = load('reader_load'               ,(Reader,P(c_char)))

card_mfplus_personalize = load('card_mfplus_personalize'   ,(Reader,P(Card)))
card_scan               = load('card_scan'                 ,(Reader,P(Card),))
card_reset              = load('card_reset'                ,(Reader,P(Card),))
card_sector_auth        = load('card_sector_auth'          ,(Reader,P(Card),P(Sector),))
card_block_read         = load('card_block_read'           ,(Reader,P(Sector),c_uint8,c_uint8,))
card_block_write        = load('card_block_write'          ,(Reader,P(Sector),c_uint8,c_uint8,))
card_sector_read        = load('card_sector_read'          ,(Reader,P(Sector),c_uint8,))
Exemple #4
0
        ("validated_time", TIME),
        ("hall_id", c_uint16),
        ("device_type", c_uint16),
        ("device_number", c_uint16),
    ]

    def __init__(self):
        self.aidpix = AIDPIX(0xD01, 0x300)
        self.validated_date = DATE()
        self.validated_time = TIME()
        self.hall_id = config.hall_id
        self.device_type = config.device_type
        self.device_number = config.hall_device_id


card_read_ulight = load("card_read_ulight", (Reader, P(AIDPIX), P(IN_TCULIGHTREAD)))
card_activate_ulight = load("card_activate_ulight", (Reader, P(IN_TCULIGHTACTIV)))


def read(card):
    u = IN_TCULIGHTREAD()
    ret = card_read_ulight(card.reader, AIDPIX(0xD01, 0x300), u)

    if ret:
        raise ULightError("Cannot read Mifare Ultralight contract")

    card.contract_list = [u.aidpix.value()]
    card.aspp = u.aspp.copy()

    begin = DATE(date=datetime(year=u.year + 2000, month=u.month, day=1))
    end = DATE(date=datetime(year=u.year + 2000, month=u.month, day=monthrange(u.year, u.month)[1]))