基于机智云物联网平台MCU模式基础教程及远程OTA( 四 )


app.h
1.
/**2.****************************************************3.*FileName:gpio.h4.*Description:Thisfilecontainsallthefunctionsprototypesfor5.*thegpio6.****************************************************7.**Thisnoticeappliestoanyandallportionsofthisfile8.*thatarenotbetweencommentpairsUSERCODEBEGINand9.*USERCODEEND.Otherportionsofthisfile,whether10.*insertedbytheuserorbysoftwaredevelopmenttools11.*areownedbytheirrespectivecopyrightowners.12.*13.*COPYRIGHT(c)2019STMicroelectronics14.*15.*Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,16.*arepermittedprovidedthatthefollowingconditionsaremet:17.*1.Redistributionsofsourcecodemustretaintheabovecopyrightnotice,18.*thislistofconditionsandthefollowingdisclaimer.19.*2.Redistributionsinbinaryformmustreproducetheabovecopyrightnotice,20.*thislistofconditionsandthefollowingdisclaimerinthedocumentation21.*and/orothermaterialsprovidedwiththedistribution.22.*3.NeitherthenameofSTMicroelectronicsnorthenamesofitscontributors23.*maybeusedtoendorseorpromoteproductsderivedfromthissoftware24.*withoutspecificpriorwrittenpermission.25.*26.*THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"27.*ANDANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THE28.*IMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEARE29.*DISCLAIMED.INNOEVENTSHALLTHECOPYRIGHTHOLDERORCONTRIBUTORSBELIABLE30.*FORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIAL31.*DAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODSOR32.*SERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)HOWEVER33.*CAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,34.*ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSE35.*OFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.36.*37.****************************************************38.*/39.40./*Definetopreventrecursiveinclusion-------------------------------------*/41.#ifndef__app_H42.#define__app_H43.#ifdef__cplusplus44.extern"C"{45.#endif46.47./*Includes------------------------------------------------------------------*/48.#include"main.h"49.#include<stdio.h>50.#include<string.h>51.52.53.voidAPP_Process(void);54.55.#ifdef__cplusplus56.}57.#endif58.#endif/*__pinoutConfig_H*/59.60./**61.*@}62.*/63.64./**65.*@}66.*/67.68./****************(C)COPYRIGHTSTMicroelectronics****ENDOFFILE***/复制代码
gagent_md5驱动编写
gagent_md5.c
1.
#include<string.h>2.#include"gagent_md5.h"3.unsignedcharPADDING[]={0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};7.voidGAgent_MD5Init(MD5_CTX*context)8.{9.context->count[0]=0;10.context->count[1]=0;11.context->state[0]=0x67452301;12.context->state[1]=0xEFCDAB89;13.context->state[2]=0x98BADCFE;14.context->state[3]=0x10325476;15.}16.voidGAgent_MD5Update(MD5_CTX*context,unsignedchar*input,unsignedintinputlen)17.{18.unsignedinti=0,index=0,partlen=0;19.index=(context->count[0]>>3)&0x3F;20.partlen=64-index;21.context->count[0]+=inputlen<<3;22.if(context->count[0]<(inputlen<<3))23.context->count[1]++;24.context->count[1]+=inputlen>>29;25.if(inputlen>=partlen)26.{27.memcpy(&context->buffer[index],input,partlen);28.GAgent_MD5Transform(context->state,context->buffer);29.for(i=partlen;i+64<=inputlen;i+=64)30.GAgent_MD5Transform(context->state,&input[i]);31.index=0;32.}33.else34.{35.i=0;36.}37.memcpy(&context->buffer[index],&input[i],inputlen-i);38.}39.voidGAgent_MD5Final(MD5_CTX*context,unsignedchardigest[16])40.{41.unsignedintindex=0,padlen=0;42.unsignedcharbits[8];43.index=(context->count[0]>>3)&0x3F;44.padlen=(index<56)?(56-index):(120-index);45.GAgent_MD5Encode(bits,context->count,8);46.GAgent_MD5Update(context,PADDING,padlen);47.GAgent_MD5Update(context,bits,8);48.GAgent_MD5Encode(digest,context->state,16);49.}50.voidGAgent_MD5Encode(unsignedchar*output,unsignedint*input,unsignedintlen)51.{52.unsignedinti=0,j=0;53.while(j<len)54.{55.output[j]=input[i]&0xFF;56.output[j+1]=(input[i]>>8)&0xFF;57.output[j+2]=(input[i]>>16)&0xFF;58.output[j+3]=(input[i]>>24)&0xFF;59.i++;60.j+=4;61.}62.}63.voidGAgent_MD5Decode(unsignedint*output,unsignedchar*input,unsignedintlen)64.{65.unsignedinti=0,j=0;66.while(j<len)67.{68.output[i]=(input[j])|69.(input[j+1]<<8)|70.(input[j+2]<<16)|71.(input[j+3]<<24);72.i++;73.j+=4;74.}75.}76.voidGAgent_MD5Transform(unsignedintstate[4],unsignedcharblock[64])77.{78.unsignedinta=state[0];79.unsignedintb=state[1];80.unsignedintc=state[2];81.unsignedintd=state[3];82.unsignedintx[64];83.GAgent_MD5Decode(x,block,64);84.FF(a,b,c,d,x[0],7,0xd76aa478);/*1*/85.FF(d,a,b,c,x[1],12,0xe8c7b756);/*2*/86.FF(c,d,a,b,x[2],17,0x242070db);/*3*/87.FF(b,c,d,a,x[3],22,0xc1bdceee);/*4*/88.FF(a,b,c,d,x[4],7,0xf57c0faf);/*5*/89.FF(d,a,b,c,x[5],12,0x4787c62a);/*6*/90.FF(c,d,a,b,x[6],17,0xa8304613);/*7*/91.FF(b,c,d,a,x[7],22,0xfd469501);/*8*/92.FF(a,b,c,d,x[8],7,0x698098d8);/*9*/93.FF(d,a,b,c,x[9],12,0x8b44f7af);/*10*/94.FF(c,d,a,b,x[10],17,0xffff5bb1);/*11*/95.FF(b,c,d,a,x[11],22,0x895cd7be);/*12*/96.FF(a,b,c,d,x[12],7,0x6b901122);/*13*/97.FF(d,a,b,c,x[13],12,0xfd987193);/*14*/98.FF(c,d,a,b,x[14],17,0xa679438e);/*15*/99.FF(b,c,d,a,x[15],22,0x49b40821);/*16*/100.101./*Round2*/102.GG(a,b,c,d,x[1],5,0xf61e2562);/*17*/103.GG(d,a,b,c,x[6],9,0xc040b340);/*18*/104.GG(c,d,a,b,x[11],14,0x265e5a51);/*19*/105.GG(b,c,d,a,x[0],20,0xe9b6c7aa);/*20*/106.GG(a,b,c,d,x[5],5,0xd62f105d);/*21*/107.GG(d,a,b,c,x[10],9,0x2441453);/*22*/108.GG(c,d,a,b,x[15],14,0xd8a1e681);/*23*/109.GG(b,c,d,a,x[4],20,0xe7d3fbc8);/*24*/110.GG(a,b,c,d,x[9],5,0x21e1cde6);/*25*/111.GG(d,a,b,c,x[14],9,0xc33707d6);/*26*/112.GG(c,d,a,b,x[3],14,0xf4d50d87);/*27*/113.GG(b,c,d,a,x[8],20,0x455a14ed);/*28*/114.GG(a,b,c,d,x[13],5,0xa9e3e905);/*29*/115.GG(d,a,b,c,x[2],9,0xfcefa3f8);/*30*/116.GG(c,d,a,b,x[7],14,0x676f02d9);/*31*/117.GG(b,c,d,a,x[12],20,0x8d2a4c8a);/*32*/118.119./*Round3*/120.HH(a,b,c,d,x[5],4,0xfffa3942);/*33*/121.HH(d,a,b,c,x[8],11,0x8771f681);/*34*/122.HH(c,d,a,b,x[11],16,0x6d9d6122);/*35*/123.HH(b,c,d,a,x[14],23,0xfde5380c);/*36*/124.HH(a,b,c,d,x[1],4,0xa4beea44);/*37*/125.HH(d,a,b,c,x[4],11,0x4bdecfa9);/*38*/126.HH(c,d,a,b,x[7],16,0xf6bb4b60);/*39*/127.HH(b,c,d,a,x[10],23,0xbebfbc70);/*40*/128.HH(a,b,c,d,x[13],4,0x289b7ec6);/*41*/129.HH(d,a,b,c,x[0],11,0xeaa127fa);/*42*/130.HH(c,d,a,b,x[3],16,0xd4ef3085);/*43*/131.HH(b,c,d,a,x[6],23,0x4881d05);/*44*/132.HH(a,b,c,d,x[9],4,0xd9d4d039);/*45*/133.HH(d,a,b,c,x[12],11,0xe6db99e5);/*46*/134.HH(c,d,a,b,x[15],16,0x1fa27cf8);/*47*/135.HH(b,c,d,a,x[2],23,0xc4ac5665);/*48*/136.137./*Round4*/138.II(a,b,c,d,x[0],6,0xf4292244);/*49*/139.II(d,a,b,c,x[7],10,0x432aff97);/*50*/140.II(c,d,a,b,x[14],15,0xab9423a7);/*51*/141.II(b,c,d,a,x[5],21,0xfc93a039);/*52*/142.II(a,b,c,d,x[12],6,0x655b59c3);/*53*/143.II(d,a,b,c,x[3],10,0x8f0ccc92);/*54*/144.II(c,d,a,b,x[10],15,0xffeff47d);/*55*/145.II(b,c,d,a,x[1],21,0x85845dd1);/*56*/146.II(a,b,c,d,x[8],6,0x6fa87e4f);/*57*/147.II(d,a,b,c,x[15],10,0xfe2ce6e0);/*58*/148.II(c,d,a,b,x[6],15,0xa3014314);/*59*/149.II(b,c,d,a,x[13],21,0x4e0811a1);/*60*/150.II(a,b,c,d,x[4],6,0xf7537e82);/*61*/151.II(d,a,b,c,x[11],10,0xbd3af235);/*62*/152.II(c,d,a,b,x[2],15,0x2ad7d2bb);/*63*/153.II(b,c,d,a,x[9],21,0xeb86d391);/*64*/154.state[0]+=a;155.state[1]+=b;156.state[2]+=c;157.state[3]+=d;158.}复制代码