复旦微电子CPU卡FMCOS协议封装

本文档详细介绍了复旦微电子的CPU卡FMCOS协议封装库,包括头文件fmcos.h和源文件fmcos.cpp的内容。提供了如初始化、擦除文件、读写文件、创建文件系统、外部认证等关键命令的实现。
摘要由CSDN通过智能技术生成

头文件fmcos.h

 

#ifndef _FM_COS_H_
#define _FM_COS_H_


#define SW_OK           (0x9000)


// FMCos命令集
namespace FMCos
{
    // PCB初始化
    void pcbInit();

    // 擦除当前DF下所有文件(不包含Df目录本身)
    int eraseCommand(quint8* cmd);

    // 请求一个用于线路保护过程的随机数
    int getChallengeCommand(quint8* cmd, quint8 len);

    // 读取二进制文件内容
    int readBinrayCommand(quint8* cmd, quint16 offset, quint8 len);
    // 更新二进制文件内容
    int writeBinaryCommand(quint8* cmd, quint16 offset, const quint8* data, quint8 len);

    // 在密钥文件中增加密钥(密钥长度8字节)
    int writeLineKeyCommand(quint8* cmd, quint8 keyId, const quint8* key);
    int writeExternalKeyCommand(quint8* cmd, quint8 keyId, const quint8* key);
    int writeKeyCommand(quint8* cmd, quint8 keyId, quint8 type, const quint8* key);

    // 通过文件标识选择文件
    int selectFileCommand(quint8* cmd, quint16 fileId);

    // 建立文件系统,包含MF,DF和EF
    int createMfFileCommand(quint8* cmd);
    int createDfFileCommand(quint8* cmd, quint16 fileId, quint16 size, quint8 appId);

    int createKeyFileCommand(quint8* cmd, quint16 fileId, quint16 size);
    int createBinaryFileCommand(quint8* cmd, quint16 fileId, quint16 size);
    int createEfFileCommand(quint8* cmd, quint16 fileId, quint8 type, quint16 size);

    // 外部认证
    int externalAuthenticateCommand(quint8* cmd, quint8 keyId, const quint8* data);

    // 命令:CLA INS P1 P2 00,应答:SW1 SW2
    int command(quint8* cmd, quint8 cla, quint8 ins, quint8 p1, quint8 p2);
    // 命令:CLA INS P1 P2 Le,应答:Le 字节DATA SW1 SW2
    int command(quint8* cmd, quint8 cla, quint8 ins, quint8 p1, quint8 p2, quint8 le);
    // 命令:CLA INS P1 P2 Lc DATA,应答:SW1 SW2
    int command(quint8* cmd, quint8 cla, quint8 ins, quint8 p1, quint8 p2, quint8 lc, const quint8* data);
    // 命令:CLA INS P1 P2 Lc DATA Le,应答:Le 字节DATA SW1 SW2<

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值